- Home /
help with UCE0001: ';' expected. Insert a semicolon at the end
i have an error that says Assets/My Stuff/scripts/dooropen.js(21,64): UCE0001: ';' expected. Insert a semicolon at the end.
if(hit.gameObject.tag == "CrateHealth")
{
Destroy(hit.gameObject);
health += 50;
GameObject.Find("GUI_Lives").guiTexture.texture "" + health;
}
can someone tell me what is wrong please
In the future, please try to put a better title on your questions. In this case, for example, even putting UCE0001: ';' expected. Insert a semicolon at the end.
would have been better; "help with scripting" doesn't describe anything about your issue.
Pro tip (for the third time today): The error tells you on which line the compiler found a problem. In your case it is on line 21 (and column 64). Double-clicking on the error in Unity will bring up a text editor with the cursor on the problem line. When you post questions to this site it helps enormously if you can add a comment to the code with some indication on which line the error was on. In your code example there is no line 21, so myself and others on this site have to guess where your problem lies. It's crazy to not give us the extra information and only makes people less likely to help you.
$$anonymous$$aybe adding (Line 21, col 64) to the compiler error would help people realize this. Just a thought. :)
Uhm... assumption: You have a GUI-Text (or something) that displays your current health-amount. you want to add "50" to the displayed number?
Ins$$anonymous$$d of texture, you need to access the displayed text (most likely a String-variable?).
But adding a number to a String doesn't work that easy either.
Hmm... trying to help you like this won't work out. You have to explain more...
Greetz, $$anonymous$$y.
Answer by DaveA · Jul 28, 2011 at 04:42 PM
.texture "" +
what's with the quotes?
And why bother to Find if you aren't going to assign it to something?
And, you can't add an integer to a texture anyway.
What are you intending to do, maybe we can give you exact syntax.
Answer by Chris D · Jul 28, 2011 at 04:45 PM
GameObject.Find("GUI_Lives").guiTexture.texture "" + health;
This line doesn't do anything. Correct your code and it'll hopefully go away.
The error is saying that the compiler expects a semicolon on line 26 which, I can only assume, is this line. The way you've written that line doesn't make sense; what were you trying to do?
Answer by SilverTabby · Jul 28, 2011 at 04:46 PM
This is the line with the problem:
GameObject.Find("GUI_Lives").guiTexture.texture "" + health;
You are trying to put a string into a Texture field with ""+health
, but the compiler is looking to either return the value of guiTexture.texture, or assign into the value.
It does not see an assignment so it returns the value of guiTexture. Then, it sees you trying to concatenate a String and a number. That has nothing to do with guiTextures, so the compiler looks at it like a new line. But there is no semicolon separating the lines, so that is when you get your error.
Fixing:
First, try using a GUIText Object instead of a GUITexture like you are using. A GUIText allows you to put text on the screen while a GUITexture only allows you to put a premade image on the screen.
make sure you have an = sign if you are changing a value. It will give you a more descriptive error message.
thanks you guys i removed the quotes but now it says
Assets/$$anonymous$$y Stuff/scripts/dooropen.js(21,66): BCE0034: Expressions in statements must only be executed for their side-effects.
Yeah, but now your problem is that the line of code does not make sense. As ChrisD said, your code doesn't do anything. You find a game object, access it's guiTexture, then the texture on the guiTexture. You add health. You don't store the result in any variable. And as DaveA said, what does it mean to add an integer to a texture?
Your answer
Follow this Question
Related Questions
Desintergrate Enemies on Dying 4 Answers
Collision Detector script 1 Answer
script help 2 Answers
whats wrong wrong with my script 4 Answers
at booster to an object 0 Answers