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
Move Player / Remove Timers
Adrianis Offline
Senior Member

Posts: 620
Threads: 6
Joined: Feb 2012
Reputation: 27
#11
RE: Move Player / Remove Timers

Dude(s), you don't need to run your timers like that. If you look at my example again, you can see that the first timer sets off the second function, and that function adds a timer to call itself, not the previous function again, and will keep calling itself, that way you keep all your code to 1 function rather than switching between them constantly (which is delaying you're loop)

Rewrote your code to demonstrate
void TurnAround(string &in asTimer)
{
    [...]
    AddTimer("Start", 0.5f, "RepeatWalking");
    AddTimer("", 1.5f, "StopEverything");
}

void RepeatWalking(string &in asTimer)
{
    MovePlayerForward(5.0f);
    AddTimer("Repeat", 0.01f, "RepeatWalking");
}

void StopEverything(string &in asTimer)
{
    [...]
    RemoveTimer("Repeat");
}

Hope that clears things up. Nice work on finding that solution



JAP, there's a different problem with the code you wrote,
void StartWalking(string &in asTimer)
{
    MovePlayerForward(5.0f);
    AddTimer("", 0.01f, "RepeatWalking");
}

void RepeatWalking(string &in asTimer)
{
    AddTimer("RepeatWalk", 0.01f, "StartWalking");
    AddTimer("", 3.0f, "StopWalking");
}
If you think about this, RepeatWalking is going to get called roughly 300 times before the first call to StopWalking.
This means that 300 timers are being declared that will all call StopWalking, which means another 300 timers are getting set up to call GiveControlBack.
The code in those functions won't run into any problems due to being called so many times, but I thought I would point out the issue for you in case you do this again in the future with code that will cause problems

(This post was last modified: 05-22-2013, 01:03 PM by Adrianis.)
05-22-2013, 01:03 PM
Find
PutraenusAlivius Offline
Posting Freak

Posts: 4,713
Threads: 75
Joined: Dec 2012
Reputation: 119
#12
RE: Move Player / Remove Timers

Sorry, but long script files screw up my mind.

"Veni, vidi, vici."
"I came, I saw, I conquered."
05-22-2013, 01:16 PM
Find




Users browsing this thread: 1 Guest(s)