Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Imhotep, opm), 785 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Loop for a fixed amount of seconds #442512
06/24/14 04:52
06/24/14 04:52
Joined: Jun 2013
Posts: 108
Alberta, Canada
C
CanadianDavid Offline OP
Member
CanadianDavid  Offline OP
Member
C

Joined: Jun 2013
Posts: 108
Alberta, Canada
Any suggestions for accurately running a while loop for a given amount of seconds without holding up the loop by using a negative wait value (ie: without using wait(-1))?

Re: Loop for a fixed amount of seconds [Re: CanadianDavid] #442515
06/24/14 06:38
06/24/14 06:38
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline
Serious User
Stansmedia  Offline
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
Something like this maybe?

Code:
var number;

function wait_seconds()
{
    wait(-3);
    number = 1;
}

function mything()
{
    number = 0;
    wait_seconds();
    while(number != 1)
    {
        //do stuff
        wait(1);
    }
}



Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: Loop for a fixed amount of seconds [Re: Stansmedia] #442517
06/24/14 08:14
06/24/14 08:14
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
a local variable can do the same work with less code.

Code:
function fnc3secs ()
{
   var clock = total_ticks + 48; // 3 sec * 16 ticks/sec
   while ( clock > total_ticks )
   {
      wait(1);
   }
}


Re: Loop for a fixed amount of seconds [Re: txesmi] #442553
06/25/14 07:13
06/25/14 07:13
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline
Expert
oliver2s  Offline
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
Code:
var timer=0; 
while(timer<3) //3 seconds
{
   timer+=time_step/16;
   wait(1);
}



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