Pause command processor, without disablement.

Started by Freydall, Tue 07/03/2006 19:01:44

Previous topic - Next topic

Freydall

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.
AEscplega is the best epic ever. Chapter I is finally finished and Chapter II is on it's way.

DoorKnobHandle

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!

Scorpiorus

#2
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]

Khris

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 :)

Scorpiorus

#4
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.

SMF spam blocked by CleanTalk