SOLVED: How to stop a timer

Started by Kamileon, Mon 16/06/2014 08:25:08

Previous topic - Next topic

Kamileon

Hey guys, here is my current dilemma: before my parrot flies into a building, he taps on the window and asks to come in. But because the timer doesn't stop, the speech keeps popping up, even if I tell cParrot to ChangeRoom. So how do I stop a timer? (been looking through past posts but they don't seem to cover randomisation as well).

Code: ags

function room_Load()
{
  SetTimer(1, 120); //Timer for parrot tapping on window.
}

function room_RepExec() //This repeats the tapping on window for the parrot until its opened.
{
    int i;
    if (IsTimerExpired(1)) {
        i = Random(2);
        if (i == 0) cParrot.SayBackground("Hello.");
        else if (i == 1) cParrot.SayBackground("Tap tap tap.");
        else cParrot.SayBackground("Let me in.");
        SetTimer(1, 120);
    }
}
It's not who I am underneath, but what I do that defines me.

Khris

The answer is a variable.

Code: ags
bool parrot_action = true;

function room_RepExec() //This repeats the tapping on window for the parrot until its opened.
{
    int i;
    if (IsTimerExpired(1)) {
        ...
        if (parrot_action) SetTimer(1, 120);
    }
}

// somewhere else in the room script
  parrot_action = false;  // stop parrot
// OR restart
  parrot_action = true;
  SetTimer(1, 1);

Kamileon

That script seems to work, but the parrot says the line once more (after it has left the room) before stopping indefinitely. Is there a way to hide or stop that one line (maybe even change that line to something like "goodbye")? Been trying to tinker with it but doesn't appear to be working for me.
It's not who I am underneath, but what I do that defines me.

Joe

Maybe:
Code: ags

if (IsTimerExpired(1) && parrot_action) {
    ...
    SetTimer(1, 120);
}

in stead of:
Code: ags

if (IsTimerExpired(1)) {
    ...
    if (parrot_action) SetTimer(1, 120);
}
Copinstar © Oficial Site

Kamileon

Yes that worked! Thank you :grin:
It's not who I am underneath, but what I do that defines me.

SMF spam blocked by CleanTalk