Timers and fun

Need help with your JScripts? Got questions concerning the DFNs? Come forward, step inside :)
Post Reply
dragon slayer
UOX3 Guru
Posts: 776
Joined: Thu Dec 21, 2006 7:37 am
Has thanked: 4 times
Been thanked: 26 times

Timers and fun

Post by dragon slayer »

So i am playing with timers and here few tricks I have learned.
function sleep(delay)
{
    var start = new Date().getTime();
    while (new Date().getTime() < start + delay);
}
That code will put the hole server to sleep
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);
        }
    }
}
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
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);
        }
    }
any way i hope this helps some one is coding timers i will keep posting more examples and fun ideas
These users thanked the author dragon slayer for the post:
Xuri
Post Reply