Gamestudio Links
Zorro Links
Newest Posts
What are you working on?
by 3run. 02/28/20 09:28
Editting
by peterhw. 02/27/20 15:20
PS1 texturing bubbling ?
by 3run. 02/27/20 13:36
enum case / if else
by danatrader. 02/27/20 00:07
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
9 registered members (3run, AndrewAMD, txesmi, Sinuhet, Quad, Zheka, FLD, Dalla, jenGs), 963 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Emrah06, zac, DebraSteed, Ricard, Apollo1
18379 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,522
Canada
Stansmedia Offline
Serious User
Stansmedia  Offline
Serious User

Joined: Mar 2003
Posts: 1,522
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,293
Hiporope and its pain
txesmi Online
Serious User
txesmi  Online
Serious User

Joined: Jun 2007
Posts: 1,293
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,257
Mainz
oliver2s Offline
Expert
oliver2s  Offline
Expert

Joined: Aug 2002
Posts: 3,257
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