Scripting a timing puzzle. Sort of SOLVED :)

Started by markbilly, Thu 15/07/2010 22:14:20

Previous topic - Next topic

markbilly

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
 

barefoot

#1
Hi

Setting up a Timer

You set a Timer by adding this where it needs to start:

Code: ags

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:

Code: ags

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

I May Not Be Perfect but I Have A Big Heart ..

markbilly

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

barefoot

Hi

Can you not just use normal talk and not use a dialog?

-barefoot-
I May Not Be Perfect but I Have A Big Heart ..

Ryan Timothy B

One solution is to just use your own Int as a timer.

Where in the dialog you set a global variable to 800:
Code: ags

  timer = 800;


In the script you could do something along the lines of this:
Code: ags

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.

Matti

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?

markbilly

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.
 

markbilly

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?
 

Matti

Why don't you 'switch' to the rep-ex using a variable? Something like this:

Pseudo-
Code: ags

// rep-ex always

if (IsTimerExpired(1)) {
  ...
  blockingaction=true;
}

// rep-ex

if (blockingaction) {
  blockingaction=false;
  // put the stuff in here
}

markbilly

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

markbilly

Sorted this now by setting up my own timer with an int.
 

Matti

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.

Dualnames

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
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk