0 registered members (),
16,643
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
condition example needs explaining
#145113
08/01/07 19:29
08/01/07 19:29
|
Joined: Sep 2003
Posts: 733 Whitefish, Montana
JazzDude
OP
User
|
OP
User
Joined: Sep 2003
Posts: 733
Whitefish, Montana
|
I don't want this function to be called when the game_state = 1,2,or 3. I don't understand why the first example doesn't work, but if written the second way, it does work. Code:
starter rival_activity() { while(game_state == 0) { snd_play(bad_news_snd,100,0); wait(1); } } Code:
starter rival_activity() { while(1) { if(game_state == 0) { snd_play(bad_news_snd,100,0); } wait(1); } }
|
|
|
Re: condition example needs explaining
[Re: JazzDude]
#145114
08/01/07 19:45
08/01/07 19:45
|
Joined: May 2005
Posts: 2,713 Lübeck
Slin
Expert
|
Expert
Joined: May 2005
Posts: 2,713
Lübeck
|
When and how do you set game_state? And what is it´s value at gamestart?
Last edited by Slin; 08/01/07 19:46.
|
|
|
Re: condition example needs explaining
[Re: JazzDude]
#145116
08/01/07 19:47
08/01/07 19:47
|
Joined: Sep 2002
Posts: 700 Orange County, CA
LogantheHogan
Developer
|
Developer
Joined: Sep 2002
Posts: 700
Orange County, CA
|
It's a bit hard to explain, but look at it this way.
while(my.flag1 == on) { ... }
this tells the engine to do something while the flag is on, but if the flag is turned off, ever, then the engine moves on and never encounters that while loop again. therefore it never checks the state of flag1, and the stuff in the brackets doesn't happen.
while(1) { if(my.flag1 == on) }
not only does that tell the engine to do something while the flag is on, but the loop continues to run even if the flag is off, checking the state of flag1 every frame. in the example at the top, the loop ends which leads to undesirable results.
SO, in your first piece of code, the engine only checks if the game_state = 0 once. If game_state != 0, even for only one frame, the function ends and never runs again. in the second piece, the function loops and always checks the game_state every frame.
Does that help?
|
|
|
Re: condition example needs explaining
[Re: JazzDude]
#145119
08/02/07 10:22
08/02/07 10:22
|
Joined: Aug 2007
Posts: 16 Texas
bigshad226
Newbie
|
Newbie
Joined: Aug 2007
Posts: 16
Texas
|
Quote:
I don't want this function to be called when the game_state = 1,2,or 3. I don't understand why the first example doesn't work, but if written the second way, it does work.
Code:
starter rival_activity() { while(game_state == 0) { snd_play(bad_news_snd,100,0); wait(1); } }
Code:
starter rival_activity() { while(1) { if(game_state == 0) { snd_play(bad_news_snd,100,0); } wait(1); } }
starter rival_activity() { while(game_state == 0)//zero was defined by some earlier function? { snd_play(bad_news_snd,100,0);//plays sound wait(1); } }
is saying while game_state is zero play the bad news sound.... basically its saying that its going to always be zero or it was set to zero by some other function. like var game_state = 0 or a function saying function function_name { game_state = 0; } ----- starter rival_activity() { while(1)//while... { if(game_state == 0)//if game state reaches zero ... { snd_play(bad_news_snd,100,0);//...then play the sound } wait(1);//wait like your supposed to  } } this is saying while this happens start the if statement which is...if game state is zero play the bad news sound...instead of saying that it was already 0 or setting it as zero. thats my understanding of it 
|
|
|
|