Page 1 of 1

2 IF statements in order QUESTION

PostPosted: Sun Dec 03, 2006 3:56 am
by HillBilly
How can I make this a working code. If the sheild is on the player can not shoot. All that the MoveOK var. is for is so the player can add controls, if it is at 0 all controls are void.

if(SheildOn==1)
{
if(MoveOK==1)
{
CreateActor("Shot", "Shot", "(none)", "(none)", 0, 0, false);
}
else
{
}
else
{
}

PostPosted: Sun Dec 03, 2006 5:58 am
by Fuzzy
if((SheildOn==1) & (MoveOK==1))
{
stuff
}

PostPosted: Sun Dec 03, 2006 1:07 pm
by HillBilly
That looks simple enough.

THANKS Fuzzy :)

PostPosted: Sun Dec 03, 2006 3:10 pm
by Game A Gogo
isn't it suppose to be
Code: Select all
if(SheildON==1 && MoveOK==1)
{
do stuff
}

PostPosted: Mon Dec 04, 2006 11:56 am
by Fuzzy
yeah, two &&. i am terrible for making that mistake. I also, out of habit, put brackets around tests, so that if you are doing double && and stuff it doesnt do it out of order.

PostPosted: Mon Dec 04, 2006 11:42 pm
by Game A Gogo
its ok, where not perfect^^

PostPosted: Tue Dec 05, 2006 2:59 am
by HillBilly
This one worked great.

if((SheildOn==1) & (MoveOK==1))
{
stuff
}


any advantages other than less brackets to use this

if(SheildON==1 && MoveOK==1)
{
do stuff
}

Just thought I would ask.

PostPosted: Tue Dec 05, 2006 7:16 am
by Fuzzy
Use && even if & works.

the benefit to using doubled brackets like that is that each comparison is made to 1, and then they are compared to each other. In certain circumstances, you may find that it calculates things out of order, as there is an order of operations, just like regular math.

so it does it like this:

((step one) step three (step two))
((Shields = true) && (Firebutton == on))


Hope that makes sense. It will not lengthen the compiled version of your game. Its like being very clear to GE what to do, in what order.

PostPosted: Tue Dec 05, 2006 3:14 pm
by HillBilly
Thanks Fuzzy, I can see where that could cause problems down the road. I will go and change it.