Frictional Games Forum (read-only)
[SCRIPT] Timer doesn't loop - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Timer doesn't loop (/thread-28778.html)



Timer doesn't loop - Neelke - 12-31-2014

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");


RE: Timer doesn't loop - 7heDubz - 12-31-2014

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);
}



RE: Timer doesn't loop - Neelke - 12-31-2014

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.