Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Timer doesn't loop
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#1
Timer doesn't loop

So I've made an updating timer which loops each 2 seconds. But for some strange reason, it doesn't loop at all. I'm guessing that I have the wrong name of timer or something, but I cannot figure out what to modify and change.

void Update(string &in asTimer)
{
    playerIsRunning = (GetPlayerSpeed() > 3) ? true : false;
    
    if(playerIsRunning)
    {
        //AddDebugMessage("Current main time divider: "+mainTimeDivider+"", false);
        if(mainTimeDivider == 10){
            //Do nothing
        }
        else
        {
            mainTimeDivider++;
        }
    }
    else
    {
        //AddDebugMessage("Current main time divider: "+mainTimeDivider+"", false);
        
        if(mainTimeDivider == 0){
            //Do nothing
        }
        else
        {
            mainTimeDivider--;
        }
    }
    
    AddDebugMessage("Current main time divider: "+mainTimeDivider+"", false);
    AddTimer("Update", 2.0f, "Update");
}

I start the timer in OnStart with Update("Update");

Derp.
12-31-2014, 01:51 AM
Find
7heDubz Offline
Posting Freak

Posts: 1,329
Threads: 40
Joined: Feb 2013
Reputation: 41
#2
RE: Timer doesn't loop

This is pure speculation,

try moving the
AddTimer("Update", 2.0f, "Update");
above the rest of the code in the Update function.

void Update(string &in asTimer)
{
    AddTimer("Update", 2.0f, "Update");
    playerIsRunning = (GetPlayerSpeed() > 3) ? true : false;
    
    if(playerIsRunning)
    {
        //AddDebugMessage("Current main time divider: "+mainTimeDivider+"", false);
        if(mainTimeDivider == 10){
            //Do nothing
        }
        else
        {
            mainTimeDivider++;
        }
    }
    else
    {
        //AddDebugMessage("Current main time divider: "+mainTimeDivider+"", false);
        
        if(mainTimeDivider == 0){
            //Do nothing
        }
        else
        {
            mainTimeDivider--;
        }
    }
    
    AddDebugMessage("Current main time divider: "+mainTimeDivider+"", false);
}

12-31-2014, 02:20 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#3
RE: Timer doesn't loop

For some reason, that did it. All other functions I implemented worked as they should and how I wanted them to be. I'm guessing one of my custom functions blocked the timer from running (how the hell that works).

Either way, for some reason that works. Thanks man.

Derp.
12-31-2014, 12:32 PM
Find




Users browsing this thread: 1 Guest(s)