Author Topic: Time delay  (Read 1199 times)

What would be the equivalent of Python's
Code: [Select]
time.sleep(Number)
in TorqueScript?

there is none.
schedule(%time, %hostObject, %function, %arguments, %arguments, %arguments);

is the best you're gonna get.

there is none.
schedule(%time, %hostObject, %function, %arguments, %arguments, %arguments);

is the best you're gonna get.
Well stuff

as a terrible alternative:

Code: [Select]
function pause(%x)
{
     %start = getrealtime();

     while(getrealtime() - %start < %x)
          continue;
     echo("done.");
}

Just making a guess as to what time.sleep does in python

Just making a guess as to what time.sleep does in python
It delays the code by a set amount of seconds
Hmm that might work

OOHHHHHH NO NO NO NO NO NONONONONOOOO

just use schedule(); (what lug said) and don't lock coding help topics

It delays the code by a set amount of seconds
Hmm that might work
so it halts all things being processed for the delay?
nexus' code is the best to simulate that, while schedule is the best for a delay on the command
doing it with the while loop will halt everything else, including the rest of the game

if you do it with the while loop, however, clients might disconnect due to timeout.

God damn it, why would you even say that Nexus. Even if you say it's a terrible alternative, it's a TERRIBLE alternative. It will literally freeze your game for that long. Not just pause the current function. If you put the sleep on too long it'll just tell you that blockland has crashed.

What would I use to check the speed of the player every 0.5 seconds using getcontrolobjectspeed();
Nevermind I got it thanks for the help
« Last Edit: July 24, 2012, 11:34:47 AM by Aide33 »

A recurring tick

The best way to set it up is something like this:
Code: [Select]
function yourModTick()
{
    cancel($YourMod::Tick::Schedule);
    $YourMod::Tick::Schedule = schedule(500,yourModTick);
    //Do whatever you need to have happen here
}
The first line of the function prevents stacking of ticks
« Last Edit: July 24, 2012, 12:19:45 PM by Treynolds416 »

If you're going to make something server-sided, you seem to want to run a check on players. Instead of having one schedule with a loop and an isObject check, creatschedules for every player using the following code. When the player object is removed it automatically stops it. Remember to start it when a player spawns, though!

function


getcontrolobjectspeed();

whoops

Instead of having one schedule with a loop and an isObject check, creatschedules for every player using the following code. When the player object is removed it automatically stops it. Remember to start it when a player spawns, though!
That's a lot more schedule loops running at once. Wouldn't it be more efficient to just have the single, global schedule loop?

That's a lot more schedule loops running at once. Wouldn't it be more efficient to just have the single, global schedule loop?
The purpose of such a thing is to have it be customizable. Since port saw that he was trying to get the speed of each player, he made a reasonable assumption that it would be a good idea to have individual loops per object to be able to have it run only when needed instead of running all the time and excluding some cases.

Different types of loops are better for different types of things, you'll have to use your discretion to determine which is appropriate.