Page 1 of 1

Please help about the thread sleep

PostPosted: Thu Aug 05, 2010 12:03 pm
by jianglong0156
I want to use the loadVars every 1 second,
like:
while(1)
{
loadVars("connect.dat","player");
sleep(1000);
}

but there is no function like sleep in GE , and I don't want to
use the Timer ,because I have a lot of codes want to loadVars like this.

Is there any function like the sleep to implements it?

Re: Please help about the thread sleep

PostPosted: Thu Aug 05, 2010 2:40 pm
by savvy
use a proper timer, set the number to 1000(1 second) then in the timer add script editor: loadVars("connect.dat","player");
sleep(1000); <-whatever that does

Re: Please help about the thread sleep

PostPosted: Fri Aug 06, 2010 1:23 am
by jianglong0156
savvy wrote:use a proper timer, set the number to 1000(1 second) then in the timer add script editor: loadVars("connect.dat","player");
sleep(1000); <-whatever that does


Is there other method to implements this function ? I don't want to use the timer.

Re: Please help about the thread sleep

PostPosted: Fri Aug 06, 2010 3:56 am
by Game A Gogo
create a variable (Let's say "i")
in the draw actor, have
Code: Select all
if(i>=real_fps*1)//change 1 for the number of seconds, or remove the multiplication if you're going to keep this at one
{
loadVars("connect.dat","player");
i=0;
}
i++;

Re: Please help about the thread sleep

PostPosted: Fri Aug 06, 2010 4:17 am
by DilloDude
In this case, I'd probably use a constant (30, or whatever the framerate is) rather than using real_fps, as using real_fps will give you "real" time, rather than game time. Game time is generally better to work with for in-game stuff, because it's always synchronized with itself, even when the game lags.

If you wanted to use "real" time, you're probably better of making "i" a real number...
Code: Select all
if (i >= 30)
{
    loadVars("connect.dat","player");
    i=0;
}
i += 30 / real_fps;

That way it's updating real time with the framerate, and will more accurately stick to one second intervals.

Re: Please help about the thread sleep

PostPosted: Fri Aug 06, 2010 8:03 am
by jianglong0156
Thank you for the help :D

Re: Please help about the thread sleep

PostPosted: Sun Aug 08, 2010 9:07 am
by Hblade
I didnt know there was a "sleep()" function O.o

Re: Please help about the thread sleep

PostPosted: Sun Aug 08, 2010 12:25 pm
by Game A Gogo
I guess I'll clarify, the sleep command existed since the command prompt terminals. (since programming pretty much) It is used to idle the system from any process for an amount of time, back in the days, this was a very useful functions. But now it is mostly obsolete because it halts processing, thus why it's not in GE.

my information may be incorrect, but this is what I know of this o|