Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Freydall on Tue 07/03/2006 19:01:44

Title: Pause command processor, without disablement.
Post by: Freydall on Tue 07/03/2006 19:01:44
Is there a way of pausing the command processor but without disabling anything the player character does? I'm probably doing the wrong thing, I want there to be a limited time to click on a hotspot.
Title: Re: Pause command processor, without disablement.
Post by: DoorKnobHandle on Tue 07/03/2006 19:03:16
Use Timers (look them up in the manual - F1) or count the frames manually (which I wouldn't necessarily recommend for a beginner).

Good luck and ask if you have trouble with timers!
Title: Re: Pause command processor, without disablement.
Post by: Scorpiorus on Wed 08/03/2006 20:40:03
Yeah, and also you probably need some flag variable, for example:

At the top of room script:

// indicates if clicking over the hotspot is allowed;
// it's initally set to false just to avoid clicking before timer actually starts
bool allow_hotspot_click = false;


On some event when you want to start your timer ticking (such as player interacts an object or enters room or whatever):

// set timer#1 to tick for 200 game loops...
SetTimer(1, 200);

// ...and at the same time allow clicking
allow_hotspot_click = true;


Room repeatedly execute:

// if clicking is allowed and timer has just expired:
if ( IsTimerExpired(1) && allow_hotspot_click == true)
{
   Display("Out of time!");

   // forbit further clicking...
   // ...after time has elapsed:
   allow_hotspot_click = false;
}


On click over (interact) hotspot:

// if clicking is allowed and timer hasn't yet expired:
if (allow_hotspot_click == true)
{
   Display("Just in time!");
      
   // we don't want to permit clicking more than once,
   // so disallow it from now on
   allow_hotspot_click = false;
}


[edit to remove IsTimerExpired check from hotspot script as it may possibly cause problems]
Title: Re: Pause command processor, without disablement.
Post by: Khris on Wed 08/03/2006 20:55:59
Correct me if I'm wrong:
The interact hotspot script doesn't have to check if the timer is expired since only if it isn't yet allow_hotspot_click equals true.

There's another reason not to check it:
In the (extremely unlikely, I know) case of the player clicking on the hotspot right when the timer expires but before the repeatedly_execute catched it, the time limit would be disabled.

Of course, clicking right between two specific 1/40s of a second is nearly impossible to achieve.

Just ignore this gibberish :)
Title: Re: Pause command processor, without disablement.
Post by: Scorpiorus on Wed 08/03/2006 22:09:38
Hehe, yeah well spotted, thanks. I tried to be precise to not count a click if timer has just expired (since I don't remember the exact sequence event functions are called in) but forgot that IsTimerExpired is actually a function with side effects. :)

[edit] I've updated the above script.