I've got a puzzle I need to (finish) scripting where you have a certain amount of time to do something.
I basically need:
1. You cause char to move (done this bit)
2. Have 20 secs to do something whilst they are gone.
3. After 20 secs, the char moves back.
Haven't got a clue where to start, because Wait() blocks other events and all the solutions to a "non-blocking wait" involve something repeating over and over - which this doesn't.
Thanks in advance for the help, everyone! :)
SEE BOTTOM FOR NEW PROBLEM
Hi
Setting up a Timer
You set a Timer by adding this where it needs to start:
SetTimer(1,800);
1= Timer number and 800 is loops...40 loops a second.. so 20 seconds =800.
Then you need to put this in the Repeatedly execute Event of that Room:
function room_RepExec()
{
if (IsTimerExpired(1)) {
PUT HERE WHAT YOU WANT TO HAPPEN AFTER THE 20 SECONDS IS UP
}
}
if you want the Timer to Repeat simply add 'SetTimer' again at the end.
Check out:
'SetTimer' and 'IsTimerExpired' in the Manual.
Hope this helps..
Can't believe I overlooked that! :-\
One problem I am having though is it doesn't seem to work because I set the timer during a dialogue...
Hi
Can you not just use normal talk and not use a dialog?
-barefoot-
One solution is to just use your own Int as a timer.
Where in the dialog you set a global variable to 800:
timer = 800;
In the script you could do something along the lines of this:
if (timer>0)
{
timer--;
if (timer==0) doWhatever;
}
Perhaps running that in the global script repeatedly_execute if the player isn't only in that one room under this time restraint.
Quote from: markbilly on Thu 15/07/2010 22:51:08
One problem I am having though is it doesn't seem to work because I set the timer during a dialogue...
Why don't you set the timer the moment the other char is gone? Or right after the dialog?
I put the stuff in repeatedly_execute_always and it works. So I don't think it was the dialogue that was a problem. Weird.
Anyway, thanks for that.
Ryan, your idea is what I looked at first and that works fine too. I just didn't get it quite right first time.
OK, I've had another problem with this.
After the timer is up, I want to do a load of things that block.
Unfortunately, the IsTimerExpired check is in repeatedly_execute_always and so I can't run anything that is blocking from there. I also can't run a function and put it all in there.
What can I do instead?
Why don't you 'switch' to the rep-ex using a variable? Something like this:
Pseudo-
// rep-ex always
if (IsTimerExpired(1)) {
...
blockingaction=true;
}
// rep-ex
if (blockingaction) {
blockingaction=false;
// put the stuff in here
}
Tried that already. It just doesn't do anything then, for some reason.
I've just done some testing. Basically, something is making the timer run forever, even though I've set it to 20 seconds.
Sorted this now by setting up my own timer with an int.
Quote from: markbilly on Fri 23/07/2010 12:39:30
Sorted this now by setting up my own timer with an int.
Yep, I do that all the time too. Never used the timer function.
Good to hear you solved it.
Quote from: Mr. Matti on Fri 23/07/2010 13:00:28
Quote from: markbilly on Fri 23/07/2010 12:39:30
Sorted this now by setting up my own timer with an int.
Yep, I do that all the time too. Never used the timer function.
Good to hear you solved it.
We all do that. Just make an integer array and a custom function out of that if it helps you..but simple timers like
int has_player_f$^&*_up are priceless. :D