If statement for checking multiple things

Subscribe to If statement for checking multiple things 15 posts, 9 voices

Sign in to reply


 
avatar for dasmitimsad dasmitimsad 1510 posts
Flag Post

Just wondering if this is right:

if(inmovie, upgrading, attacking, defending = false){

I am only starting the basic structure of the script so I can’t test it out quickly. But I have declared all these boolean values so would this work? Or am I just making something up. And if it wouldn’t work what would?

 
avatar for Rameares Rameares 63 posts
Flag Post

I don’t think so normally you would need and and or operators in an if statement to check multiple conditions.

if (inmovie && upgrading && Attacking && !defending);

the && is the and operator.
the ! is the not operator changes the bolean value of the varible it precedes.

if the above code doesn’t work try


if((inmovie && upgrading) && (attacking && !defending)

 
avatar for dasmitimsad dasmitimsad 1510 posts
Flag Post

Well, I can’t really test it out at the moment because I’m just writing the script in advance. So I wouldn’t need the = false at the end or?

 
avatar for Rameares Rameares 63 posts
Flag Post

the ! is doing it for you it’s evaluating it to the oposite of waht it is.

saying it out loud would be “if not defending”

so !defending is the same as defending = false

 
avatar for SavageWolf SavageWolf 692 posts
Flag Post

!defending is the same as defending == false, defending = false is wrong and will return true.

 
avatar for dasmitimsad dasmitimsad 1510 posts
Flag Post

Ohk I get it. Thankyou guys :)

 
avatar for Rameares Rameares 63 posts
Flag Post
Originally posted by SavageWolf:

!defending is the same as defending == false, defending = false is wrong and will return true.

good spot there = will make the left side equal the right its == for a check

 
avatar for Nabb Nabb 985 posts
Flag Post
Originally posted by SavageWolf:

defending = false is wrong and will return true.

Nope.

 
avatar for bLasTamos bLasTamos 546 posts
Flag Post

Yeah defending = false will obviously return false, it’s the value of the expression because it’s the value operand of the assignment.

 
avatar for Kingfish34 Kingfish34 135 posts
Flag Post

Correct… Returns the value in the =’s which is false.

= assignment Operator

Usage expression1 = expression2

Language Version : ActionScript 3.0
Flash Player 8.5 : Flash Player 9

Assigns the value of expression2 (the operand on the right) to the variable, array element, or property in expression1. Assignment can be either by value or by reference. Assignment by value copies the actual value of expression2 and stores it in expression1. Assignment by value is used when expression2 is a primitive value, which means that its data type is either Boolean, Number, int, uint, or String. Assignment by reference stores a reference to expression2 in expression1. Assignment by reference is commonly used with the new operator. The new operator creates an object in memory, and a reference to that location in memory is assigned to a variable.

Note: In ActionScript 3.0 all values (including primitive values) are objects, and all assignment is done by reference, but primitive objects have special operators that allow them to behave as if they are assigned by value.

Operands expression1:* — A variable, element of an array, or property of an object.
expression2:* — A value of any type.

Result Object — The assigned value, expression2.

 
avatar for LOL_at_U LOL_at_U 5 posts
Flag Post

copypast

Originally posted by Kingfish34:

Correct… Returns the value in the =’s which is false.


= assignment Operator


Usage expression1 = expression2


Language Version : ActionScript 3.0

Flash Player 8.5 : Flash Player 9


Assigns the value of expression2 (the operand on the right) to the variable, array element, or property in expression1. Assignment can be either by value or by reference. Assignment by value copies the actual value of expression2 and stores it in expression1. Assignment by value is used when expression2 is a primitive value, which means that its data type is either Boolean, Number, int, uint, or String. Assignment by reference stores a reference to expression2 in expression1. Assignment by reference is commonly used with the new operator. The new operator creates an object in memory, and a reference to that location in memory is assigned to a variable.


Note: In ActionScript 3.0 all values (including primitive values) are objects, and all assignment is done by reference, but primitive objects have special operators that allow them to behave as if they are assigned by value.


Operands expression1:* — A variable, element of an array, or property of an object.

expression2:* — A value of any type.


Result Object — The assigned value, expression2.

copypasta

 
avatar for dasmitimsad dasmitimsad 1510 posts
Flag Post

Okay I have another question. Would this one work for finding if its true? I want to have to check them seperately instead of all at the same time:

if (inmovie or upgrading or attacking or defending){
 
avatar for ssjskipp ssjskipp 159 posts
Flag Post

that should work fine, just as long as ‘or’ is still allowed. If not, the syntax for an ‘or’ operator is ||.

if (inmovie || upgrading || arracking || defending){
//stuff
}
 
avatar for dasmitimsad dasmitimsad 1510 posts
Flag Post

Cool thanks

 
avatar for starfiregold starfiregold 147 posts
Flag Post

I shudder to think of the hot ugly mess of spaghetti code that’s forcing you to write an IF statement like that.

Sign in to reply


Click Here