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).
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);
}
}
The answer is a variable.
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);
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.
Maybe:
if (IsTimerExpired(1) && parrot_action) {
...
SetTimer(1, 120);
}
in stead of:
if (IsTimerExpired(1)) {
...
if (parrot_action) SetTimer(1, 120);
}
Yes that worked! Thank you :grin: