- Home /
The question is answered, right answer was accepted
[JavaScript Error] BCE0043: Unexpected token:
I'm a noob.. This is the errors i got 1) Assets/Txt.js(2,1): BCE0043: Unexpected token: [.
2)Assets/Txt.js(5,1): BCE0043: Unexpected token: ]. 3)Assets/Txt.js(9,2): BCE0043: Unexpected token: [. 4)Assets/Txt.js(12,2): BCE0043: Unexpected token: ]. I'm doing a start menu for my game.. This is my code
function OnMouseEnter()
[
//change the color of text
renderer.material.color = Color.red
];
function OnMouseExit()
[
//change the color of text
renderer.material.color = Color.white
];
Answer by Statement · Dec 22, 2013 at 05:58 PM
Your immediate problem is that you use [ and ] when you should be using { and }.
Functions doesn't end with ;
I'd strongly recommend that you try to learn how to program with Unitys Javascript.
If you search answers for help on learning Javascript for Unity, you'll find a lot of resources.
Here's one, for example: How can i learn JavaScript (UnityScript) ?
Some things to keep in mind when you look for tutorials or books regarding Unitys JavaScript.
It's often called UnityScript, to solve an ambiguity with other languages that are named similarly.
So avoid confusion with JavaScript!
So avoid confusion with Java!
Hope it helps. Good luck, and pick a nice site to start learning programming.
But he is using Unityscript. And out of curiosity's sake, what are the reasons that you'd recommend one to learn it over the other languages Unity supports?
@iwaldrop: Yes, @CapitanRedRU$$anonymous$$ is using UnityScript. I have not implied that the OP was using any other language. I didn't recommend the OP to switch to another language. I recommended that the OP should reinforce their program$$anonymous$$g knowledge (in UnityScript) by learning the basics (like, the syntax, which is extremely important and one of the first things you should learn).
I will add some emphasis on my answer to try to make that a little clearer.
The reason I recommend that the OP should learn it more thoroughly is to help the OP avoiding getting stuck on basics.
So I tried to be helpful here.
a solution to the current immediate problem was presented.
a method of reinforcing the chosen coding path was presented, to provide a means of self-help to the user.
a warning about common ambiguities was presented so user doesn't spend time reading the wrong tutorials or spending money on buying the wrong kinds of books.
If you'd ask me, I wouldn't recommend UnityScript. I think personally that it's far better to learn C# as you can directly make use of your skills outside of Unity and that most (based on my experience working with a range of studios) professional users use C#.
Some things are better written in UnityScript than C#.
Some things are better written in C# than UnityScript.
I have very little experience with Boo, and I won't comment on that.
In the end, I've found there are more benefits using C# than US.
US has missing features, such as extension methods to name one.
I agree with @Statement. If you'd look through just one page of the Unity Script Reference, you'd know how to correctly use a function in UnityScript. Check out an example.
Answer by clunk47 · Dec 23, 2013 at 12:00 AM
Wrong brackets, and you don't need semicolon after closing bracket. You do however need a semicolon after each "INSTRUCTION (F U @Vexe)".
function OnMouseEnter()
{
renderer.material.color = Color.red;
}
Haha just an inside joke between another user and me. @Vexe saw I called instuctions commands and had something to say about it on facebook. Figured I'd correct myself and tag him is all XD
Follow this Question
Related Questions
Javascript Expecting Errors ';' & '=' 0 Answers
Setting Scroll View Width GUILayout 1 Answer
Unexpected token: private. Error. Can anyone help? 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Code Error, help please? 2 Answers