Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 14:22
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
0 registered members (), 631 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
while loop IN another while loop #343922
10/11/10 19:53
10/11/10 19:53
Joined: Jul 2009
Posts: 96
M
mEnTaL Offline OP
Junior Member
mEnTaL  Offline OP
Junior Member
M

Joined: Jul 2009
Posts: 96
I have a while loop #1 which has wait time 1 step and while loop #2 which has wait time 2 seconds and must stay INSIDE while loop#1, . And here comes the problem: the engine executes WhileLoop #1 properly, but doesn't wait 2 seconds for "#2" and executes it every frame instead!

here is a code which examinates this:

Code:
function shooting()
{
while(1)// this is while loop #2 
{
  create_bullet();
  wait(-2);
}

}


action npc()
{

while(1) //this is while loop #1 
{
  //do some stuff constantly 
  shooting(); //THIS little function is executed every frame instead of 2 sec interval >: ( 
 wait(1);
}

}


So how can I manage to execute properly while loop with 2 sec wait() time inside a while loop with 1 frame wait time?

Re: while loop IN another while loop [Re: mEnTaL] #343924
10/11/10 20:00
10/11/10 20:00
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
action npc()
{
var counter = 0;
var shooting_time = 20;//don't know the number that you need for 2 seconds
while(1)
{
counter += time_step;
if(counter > shooting_time)
{
create_bullet();
counter = 0;
}
wait(1);
}
}

Re: while loop IN another while loop [Re: Pappenheimer] #343929
10/11/10 20:38
10/11/10 20:38
Joined: Jul 2009
Posts: 96
M
mEnTaL Offline OP
Junior Member
mEnTaL  Offline OP
Junior Member
M

Joined: Jul 2009
Posts: 96
Great. Thx man

Re: while loop IN another while loop [Re: mEnTaL] #343930
10/11/10 20:38
10/11/10 20:38
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
Code:
action npc()
{
  shooting(); //place outside the inner while loop, will start a new coroutine
while(1) //this is while loop #1 
{
  //do some stuff constantly 
 wait(1);
}
}



Re: while loop IN another while loop [Re: mEnTaL] #343933
10/11/10 22:22
10/11/10 22:22
Joined: Sep 2009
Posts: 987
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 987
Budapest
Another way maybe more precise, use the built-in sys_seconds variable to detect the elapsed time, in your case 2 secs.


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

Gamestudio download | chip programmers | 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