Creating timed events

Started by 2Minis-A, Mon 31/10/2016 12:04:31

Previous topic - Next topic

2Minis-A

Hi all, I looked around in the forums but didn't manage to find a solution, hope this belongs to the beginner section~

I'm trying to create something similar to the scene in Broken Sword: Shadow of the Templars where you had to click away right after pulling the lion's tooth to avoid the falling door ( https://youtu.be/uAMENoz9NeU?t=10m47s to make it more clear). I tried to do something with timers but what I managed is nothing at all. I really had no idea how to make this work. Thanks in advance for the help~

Khris

To start the timer, call something like
Code: ags
  SetTimer(1, 100);

This line will set timer #1 to 100 frames, then start it. 100 frames means if your game uses the default speed of 40 frames per second, the timer will expire after 2.5 seconds.

To do something when the timer expires, add the Repeatedly Execute event to the room in the editor, then open the room script and add this to the room_RepExec function:
Code: ags
  if (IsTimerExpired(1)) {
    player.Say("2.5 seconds later.");
  }

The code in room_RepExec will run every frame, so as soon as the timer expires, IsTimerExpired(1) will return true and the code inside the curly brackets will run.

SMF spam blocked by CleanTalk