Page 1 of 1

Illegal use of reserved word

Posted: August 25th, 2010, 5:31 pm
by Disciple
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

Re: Illegal use of reserved word

Posted: August 26th, 2010, 12:45 pm
by Paul Tuersley
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;

Re: Illegal use of reserved word

Posted: August 26th, 2010, 1:51 pm
by Disciple
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

Re: Illegal use of reserved word

Posted: August 26th, 2010, 2:12 pm
by Paul Tuersley
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.

Re: Illegal use of reserved word

Posted: August 26th, 2010, 2:16 pm
by Disciple
Yes it does, actually just phrasing the question made me realize what the answer was. Thank you for clarifying even further

Alex