Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
0 registered members (), 16,643 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
condition example needs explaining #145113
08/01/07 19:29
08/01/07 19:29
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline OP
User
JazzDude  Offline 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 Offline
Expert
Slin  Offline
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: Slin] #145115
08/01/07 19:47
08/01/07 19:47
Joined: Mar 2006
Posts: 752
Portugal
demiGod Offline
User
demiGod  Offline
User

Joined: Mar 2006
Posts: 752
Portugal
that´s because you are changing the var game_state somewhere to a value different from zero.

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
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

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: LogantheHogan] #145117
08/01/07 19:59
08/01/07 19:59
Joined: Sep 2003
Posts: 733
Whitefish, Montana
JazzDude Offline OP
User
JazzDude  Offline OP
User

Joined: Sep 2003
Posts: 733
Whitefish, Montana
Very lucid explanation, LogantheHogan! Thank you. I got it. I hope I remember it.

Re: condition example needs explaining [Re: JazzDude] #145118
08/01/07 20:18
08/01/07 20:18
Joined: Sep 2002
Posts: 700
Orange County, CA
L
LogantheHogan Offline
Developer
LogantheHogan  Offline
Developer
L

Joined: Sep 2002
Posts: 700
Orange County, CA
Haha, glad it got the point across. God bless.

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 Offline
Newbie
bigshad226  Offline
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


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1