Please help about the thread sleep

Game Editor comments and discussion.

Please help about the thread sleep

Postby jianglong0156 » Thu Aug 05, 2010 12:03 pm

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?
jianglong0156
 
Posts: 5
Joined: Thu Aug 05, 2010 11:53 am
Score: 0 Give a positive score

Re: Please help about the thread sleep

Postby savvy » Thu Aug 05, 2010 2:40 pm

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
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: Please help about the thread sleep

Postby jianglong0156 » Fri Aug 06, 2010 1:23 am

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.
jianglong0156
 
Posts: 5
Joined: Thu Aug 05, 2010 11:53 am
Score: 0 Give a positive score

Re: Please help about the thread sleep

Postby Game A Gogo » Fri Aug 06, 2010 3:56 am

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++;
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Please help about the thread sleep

Postby DilloDude » Fri Aug 06, 2010 4:17 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Re: Please help about the thread sleep

Postby jianglong0156 » Fri Aug 06, 2010 8:03 am

Thank you for the help :D
jianglong0156
 
Posts: 5
Joined: Thu Aug 05, 2010 11:53 am
Score: 0 Give a positive score

Re: Please help about the thread sleep

Postby Hblade » Sun Aug 08, 2010 9:07 am

I didnt know there was a "sleep()" function O.o
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Please help about the thread sleep

Postby Game A Gogo » Sun Aug 08, 2010 12:25 pm

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|
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron