PDA

View Full Version : Variable Declaration and If statements


/Pyro
02-07-2003, 11:40 AM
Ok, this is kinda two questions in one. First, do you have to declare variables? I'm used to programming in Visual Basic and declaring variables before i can use them.
The reason I'm asking is because it seems to not understand the variable I am using.

It says this:
Left side of assignment operator must be variable or property.

This is the line it dosent like;
if (_x>9.1 & _x<39.1 & _y>153 & _y<231 & moboset = true) {

is there something wrong with the way my if is structured? if there is, can i nest If's inside of each other instead?

fgf
02-07-2003, 12:07 PM
= is an assignment
== is a test for equality

don't worry everybody does it.

fgf

Lolotte
02-07-2003, 12:14 PM
Hi,

First, i don't think variables name in Flash can start with an underscore. And because _x is a movieclip property (like myMc._x), you should avoid this variable name.

In your conditionnal statement, you must you use && instead of & when you want to add a condition in term of "and".

Regarding the variable, it must already exist before doing the comparison, but instanciate it with "var" is facultative (altough good practice).
When you are inside a function, the "var" serves to scope the following variable name to the function only, so in this case it is requuired if this is what you want (ie. if you have var myVariable in a function, myVariable will only be accessible to that function).

Finally, the = sign must be doubled when used in a comparison (==).

Your code could look like this:

if (myX>9.1 && myX<39.1 && myY>153 && myY<231 && moboset == true) {


Hope it helps a bit,

Lolotte

annexion
02-07-2003, 07:42 PM
if (myX>9.1 && myX<39.1 && myY>153 && myY<231 && moboset) {
}

In an if statement, there is no need for "== true". It automatically evaluates it. On the counter to that, there is !moboset, which returns true if moboset is false.

Good luck.

Lolotte
02-07-2003, 07:47 PM
You are absolutely right!!!

Thanks for reminding me.

Lolotte