Timers and fun
Posted: Mon Jul 12, 2021 2:43 am
So i am playing with timers and here few tricks I have learned.
That code will put the hole server to sleep
see how I added sleep(500); lol
here is a loop in the timer tp try to stop it for a few seconds before firing next one
any way i hope this helps some one is coding timers i will keep posting more examples and fun ideas
function sleep(delay)
{
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
{
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
function onTimer(myObj, timerID)
{
if (timerID == 1)
{
//Change lever gfx back
if (myObj.id == 0x1095)
myObj.id = 0x1093;
}
else if (timerID == 2)
{
if (ValidateObject(myObj))
{
if (myObj.z < 15)
{
myObj.z++;
myObj.StartTimer(1000, 2, true);
}
else if (myObj.z > 0)
{
sleep(5000);
myObj.TextMessage("Waited 5s");
myObj.StartTimer(5000, 3, true);
}
}
}
else if (timerID == 3)
{
if (myObj.z > 0)
{
myObj.z--;
myObj.StartTimer(1000, 3, true);
}
}
}
{
if (timerID == 1)
{
//Change lever gfx back
if (myObj.id == 0x1095)
myObj.id = 0x1093;
}
else if (timerID == 2)
{
if (ValidateObject(myObj))
{
if (myObj.z < 15)
{
myObj.z++;
myObj.StartTimer(1000, 2, true);
}
else if (myObj.z > 0)
{
sleep(5000);
myObj.TextMessage("Waited 5s");
myObj.StartTimer(5000, 3, true);
}
}
}
else if (timerID == 3)
{
if (myObj.z > 0)
{
myObj.z--;
myObj.StartTimer(1000, 3, true);
}
}
}
here is a loop in the timer tp try to stop it for a few seconds before firing next one
function onTimer(myObj, timerID)
{
if (timerID == 1)
{
//Change lever gfx back
if (myObj.id == 0x1095)
myObj.id = 0x1093;
}
else if (timerID == 2)
{
if (ValidateObject(myObj))
{
if (myObj.z < 15)
{
myObj.z++;
myObj.StartTimer(1000, 2, true);
}
else if (myObj.z > 0)
{
// Timer in loop
for (let i = 0; i < 5; i++)
{
if (i == 3)
myObj.StartTimer(5000, 3, true);
}
}
}
}
else if (timerID == 3)
{
if (myObj.z > 0)
{
myObj.z--;
myObj.StartTimer(1000, 3, true);
}
}
{
if (timerID == 1)
{
//Change lever gfx back
if (myObj.id == 0x1095)
myObj.id = 0x1093;
}
else if (timerID == 2)
{
if (ValidateObject(myObj))
{
if (myObj.z < 15)
{
myObj.z++;
myObj.StartTimer(1000, 2, true);
}
else if (myObj.z > 0)
{
// Timer in loop
for (let i = 0; i < 5; i++)
{
if (i == 3)
myObj.StartTimer(5000, 3, true);
}
}
}
}
else if (timerID == 3)
{
if (myObj.z > 0)
{
myObj.z--;
myObj.StartTimer(1000, 3, true);
}
}