I have a scenario where a character knocks on a door, and as the man comes to answer, the player has a few seconds to hide. To make it work I used a variable to enable hiding, once you knock on the door. But once the man reaches the door, if you have not already hidden, it will be too late... so I put the variable back to diable hiding.
My problem is, I don't know how to give the player a few seconds to try and hide. If I pause the command processor, the player cannot move, and I can't have him wait for the man to walk to the door, because the man will not even exist in the scene until he actually appears at the door.
My only idea is to trigger some sprite to animate in the background, out of site, for a few loops before having the man show up at the door.
Is there a simple script to add a delay between two actions without disabling the rest of the command processing?
Thanks to anyone who can help.
use repeatdly execute, When you knock on the door start a timer going, e.g.
int timer=0; //at start of room script
somewhere,
//event knock on door
timer=1;
and in
repeatedlyexecute()
{
Ã, if (timer>0)
{
Ã, Ã, timer++;
Ã, Ã, if (timer==whenever) do something;
Ã, Ã, ...
Ã, Ã,Â
Ã, Ã, if (timer==end of timelimit) timer=0;
}
}
Might need a bit of tidying up if player leaves screen during timer, maybe put timer=0 in player enters screen, whatever.
I'm sure someone will point out a module to do this but I like the hands on approach.
Another way would be to use a Timer (SetTimer() (http://www.adventuregamestudio.co.uk/manual/SetTimer.htm)), and have the old man arriving / hiding being disabled in rep_ex with IsTimerExpired() (http://www.adventuregamestudio.co.uk/manual/IsTimerExpired.htm).
Something like:
if (IsTimerExpired(1) ) {
cOld.ChangeRoom(room, x, y); //Old man enters room
hide = 0; // disable hiding
if (playerishiden == 0) { // Or however you're checking whether player is hiden
// Player ISN'T hiden.
// Do stuff
}
else { // Player IS hiden
// Do other stuff
}
}
Basically the same as Wretched's suggestion, but lets AGS do the counting down part.
Might take a bit of work to get it working just right, but it sounds like the simplest way to me.
Alright, I have started tinkering with this, but I haven't managed to get the timer going correctly. I've read the whole scripting tutorial, and I can't understand why this script isn't working...
When player clicks on hotspot 1, I should have a 10 seconds, and then see a message saying timer 1 expired.. but It's not happening. Any help would be appreciated.
// script for Hotspot 1 (Hotspot 1): Interact hotspot
SetTimer(1,400);
if (IsTimerExpired(1) == 1) {
Display("Timer 1 expired");
}
Move the following:
if (IsTimerExpired(1) == 1) {
Display("Timer 1 expired");
}
into repeatedly execute of the room.