Expressions/Scripts/Presets

Moderators: Disciple, zlovatt

 
User avatar
Disciple
Topic Author
Posts: 137
Joined: Sat Jun 05, 2004 8:05 am
Location: Los Angeles, CA
Contact:

Illegal use of reserved word

Wed Aug 25, 2010 5:31 pm

Trying this
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: Sat Jun 05, 2004 7:59 am
Location: London, UK

Re: Illegal use of reserved word

Thu Aug 26, 2010 12:45 pm

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:
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:

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

Re: Illegal use of reserved word

Thu Aug 26, 2010 1:51 pm

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: Sat Jun 05, 2004 7:59 am
Location: London, UK

Re: Illegal use of reserved word

Thu Aug 26, 2010 2:12 pm

Well, no you couldn't do this on the position property:
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
Topic Author
Posts: 137
Joined: Sat Jun 05, 2004 8:05 am
Location: Los Angeles, CA
Contact:

Re: Illegal use of reserved word

Thu Aug 26, 2010 2:16 pm

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

Alex

Who is online

Users browsing this forum: No registered users and 3 guests