Illegal use of reserved word

Moderators: Disciple, zlovatt

Post Reply
User avatar
Disciple
Posts: 137
Joined: June 5th, 2004, 8:05 am
Location: Los Angeles, CA
Contact:

Trying this

Code: Select all

if(time<4);
	{opacity=0};
else
	{opacity=100};
opacity
I get an error message for line 3 saying "illegal use of reserved word"
Line 3 is the "else"
What am I doing wrong? Is it a syntax error here?

Thanks
Alex
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Well it's kind of strange that you're using the word opacity, but that isn't it. You shouldn't have a semi-colon on the first line.

Not that this matters, but here's how I'd format it:

Code: Select all

if (time<4) {
    opacity=0;
} else {
    opacity=100;
}
opacity;
EDIT: Actually I just realised it does matter that you're using the word opacity, although that just produces the wrong result and doesn't cause an error. Try this instead:

Code: Select all

if (time<4) {
    banana=0;
} else {
    banana=100;
}
banana;
User avatar
Disciple
Posts: 137
Joined: June 5th, 2004, 8:05 am
Location: Los Angeles, CA
Contact:

Ha, so why is it that you can't use the name of the property to target itself? This doesn't seem to be the case with position or scale?

Thanks Paul

Alex
Paul Tuersley
Posts: 704
Joined: June 5th, 2004, 7:59 am
Location: London, UK

Well, no you couldn't do this on the position property:

Code: Select all

position = [0,0];
position;
Or you could, but the first line wouldn't do anything, then the second line is like saying "apply the position property's value to the position property", so the result is the same as without the expression.

In an expression you can create a new variable and assign a value to it, but you can't directly assign a value to the property. You can of course read the value of a property and you do this by using the name of the property, but it's essentially read only so it's not a good idea to try using it as a variable.

Then, the resulting value from the last line of the expression is what becomes the property's value.

Hope that makes sense.
User avatar
Disciple
Posts: 137
Joined: June 5th, 2004, 8:05 am
Location: Los Angeles, CA
Contact:

Yes it does, actually just phrasing the question made me realize what the answer was. Thank you for clarifying even further

Alex
Post Reply