SetTimer issue

Started by Anarcho, Mon 18/04/2005 02:29:20

Previous topic - Next topic

Anarcho

I'm having a problem with my script here.  The object animates, the GlobalInt is set, but the timer doesn't run out.  The object just continues to animate, and the GlobalInt isn't set back to 0.  And I've set the timer to different numbers---it's 2 here, but I've had it at 40, 200...a bunch of different numbers.

SetTimer (1, 2);
  if (IsTimerExpired (1)!=1) {
 
    SetGlobalInt(83,1);
    object[4].Visible = true;
    object[4].SetView(54);
    object[4].Animate(0, 3, eRepeat, eNoBlock);
    character[JUAREZ].ChangeView(55);
    character[JUAREZ].SpeechView = 55;
    character[JUAREZ].SetIdleView(56, 0);

   
    }   
   

  if (IsTimerExpired(1) == 1){
   
    object[4].Visible = false;
    SetGlobalInt(83,0);
    DisplaySpeech(JUAREZ, "Oh.  It's back to normal.  That was strange.");
  } 
 
 


strazer

Quote from: Manual
IsTimerExpired (int timer_id)
(...)
Note that this function will only return 1 once - after that, the timer is placed into an OFF state where it will always return 0 until restarted.

And where have you put your code?
If SetTimer is in rep_ex too, you re-set the timer every game loop, so it won't expire.

Anarcho

The code in the room script file for an object.   


strazer

Okay, I'm still not sure where you've put the different parts of your code.
You probably want to set it up like this:

Code: ags

  // script for object: Interact with object

  SetGlobalInt(83, 1);
  object[4].Visible = true;
  object[4].SetView(54);
  object[4].Animate(0, 3, eRepeat, eNoBlock);
  character[JUAREZ].ChangeView(55);
  character[JUAREZ].SpeechView = 55;
  character[JUAREZ].SetIdleView(56, 0);

  SetTimer (1, 80); // start timer that expires in 2 seconds


Code: ags

  // script for room: Repeatedly execute

  if (IsTimerExpired(1) == 1) { // if the timer is expired (will only be true once, see above)
    object[4].Visible = false;
    SetGlobalInt(83, 0);
    DisplaySpeech(JUAREZ, "Oh.  It's back to normal.  That was strange.");
  }

Anarcho

It worked.  Great!  Thanks again, Strazer.

I didn't put the second part of the code in Repeatedly execute, I just put it after the initial code.


strazer

I see. Well, the script isn't paused when you start a timer, therefore everything after your SetTimer command was executed immediately. Of course, at that point the timer had no chance to expire yet, therefore your code didn't work.
If you just want the script to pause for a moment, use the Wait command. But your game will be blocked at that point.
If you use timers, your game won't block but you have to check manually in rep_ex if the timer has expired, then execute the code you want to happen after the time has elapsed.
Just FYI. ;)

Anyway, glad it works now. :)

SMF spam blocked by CleanTalk