Frictional Games Forum (read-only)

Full Version: Timer doesn't loop
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.

Code:
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");
This is pure speculation,

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

Code:
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);
}
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.