Author Topic: Error with schedules [solved]  (Read 1026 times)

Code: [Select]
function timer(%client)
{
Cancel(%client.timer);
%client.timer = schedule(1,0,timer,%client);
%client.time += 0.001;
}

function GameConnection::EHO_startTimer(%client)
{
messageClient(%client,'MsgAdminForce',"<color:00ff00>The timer has started!");
timer(%client);
}

function GameConnection::EHO_stopTimer(%client)
{
Cancel(%client.timer);
messageClient(%client,'MsgAdminForce',"<color:00ff00>Your time was <color:ffff00> " @ %client.time @ "<color:00ff00>.");
%client.time = 0;
}

The error is that %client.time goes up by 0.1 about every half second. It's on my server right now if you want to take a look.

I will put all the code (this is part of it) into a pastebin if necessary.
« Last Edit: September 28, 2013, 07:29:54 PM by Achoo »

A better way of doing this instead of a very spammy schedule is to log the start time with either getSimTime() or getRealTime() and then subtract the start time from the end time.
Also your problem with the current script may be that it's trying to run every millisecond, but that's just a guess

New code:

Code: [Select]
function GameConnection::EHO_startTimer(%client)
{
messageClient(%client,'MsgAdminForce',"<color:00ff00>The timer has started!");
%client.firstTime = getSimTime();
}

function GameConnection::EHO_stopTimer(%client)
{
%client.secondTime = getSimTime();
%client.newTime = %client.secondTime - %client.firstTime;
%client.newTime = %client.newTime / 1000;
messageClient(%client,'MsgAdminForce',"<color:00ff00>Your time was <color:ffff00> " @ %client.newTime @ "<color:00ff00>.");
}

This does give me what I want, but its not completely accurate.
« Last Edit: September 27, 2013, 08:37:12 PM by Achoo »

Try getRealTime, getSimTime only counts game time, so if the server lags it becomes inaccurate.

Thank you, that is more accurate.
« Last Edit: September 28, 2013, 04:48:42 PM by Achoo »