2 IF statements in order QUESTION

Game Editor comments and discussion.

2 IF statements in order QUESTION

Postby HillBilly » Sun Dec 03, 2006 3:56 am

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
{
}
HillBilly
 
Posts: 68
Joined: Thu Jun 08, 2006 4:31 am
Location: OHIO, USA
Score: 4 Give a positive score

Postby Fuzzy » Sun Dec 03, 2006 5:58 am

if((SheildOn==1) & (MoveOK==1))
{
stuff
}
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby HillBilly » Sun Dec 03, 2006 1:07 pm

That looks simple enough.

THANKS Fuzzy :)
HillBilly
 
Posts: 68
Joined: Thu Jun 08, 2006 4:31 am
Location: OHIO, USA
Score: 4 Give a positive score

Postby Game A Gogo » Sun Dec 03, 2006 3:10 pm

isn't it suppose to be
Code: Select all
if(SheildON==1 && MoveOK==1)
{
do stuff
}
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby Fuzzy » Mon Dec 04, 2006 11:56 am

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby Game A Gogo » Mon Dec 04, 2006 11:42 pm

its ok, where not perfect^^
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby HillBilly » Tue Dec 05, 2006 2:59 am

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.
HillBilly
 
Posts: 68
Joined: Thu Jun 08, 2006 4:31 am
Location: OHIO, USA
Score: 4 Give a positive score

Postby Fuzzy » Tue Dec 05, 2006 7:16 am

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby HillBilly » Tue Dec 05, 2006 3:14 pm

Thanks Fuzzy, I can see where that could cause problems down the road. I will go and change it.
HillBilly
 
Posts: 68
Joined: Thu Jun 08, 2006 4:31 am
Location: OHIO, USA
Score: 4 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest