Waiting without blocking

Started by EliasFrost, Wed 01/05/2013 17:13:05

Previous topic - Next topic

EliasFrost

Hi again! I have another problem that I want to solve but I fear I'm not a good enough scripter to get the result I am looking for.

My problem is:
In my main menu, which is a room with a GUI overlay, I want to have cars driving by and then after 10 or so seconds, another car drive by, repeat. But my issue is that I can't seem to make the waiting intervals in between unblocking, the wait() command doesn't work (makes clicking the buttons unavailable) so I figured I need to use the timer commands, but I'm really unsure how to use them.

I figured I need to set it up like this:
-First the car(object) drives by (eNoBlocked) so I need a timer to determine how long time the car is driving (so that the next command isn't called directly)
-Then I need to wait for that timer to expire until I initiate the timer interval between the first car and the next one.
-After the interval timer, I position the car(object) on it's default position and redo step one and go through all steps again on repeat.

Maybe that's totally overcomplicated, but I have no clue how to script, if some kind soul would please take a little time of yours to help me out, that would be amazing!

Thank you!

Khris

In the room's onLoad:
Code: ags
  SetTimer(1, 1);


In the room's RepExec:
Code: ags
  if (IsTimerExpired(1)) {
    // car code here
    // ...
    SetTimer(1, GetGameSpeed() * 10);  // ten seconds delay
  }


If you want to do thing A, then thing B, repeat, add this at the top of the room script, outside any functions:
Code: ags
int car_event = 1;

Then where it says "// car code", put something like:
Code: ags
    if (car_event == 1) {
      // position and send off first car
      // ...
    }
    if (car_event == 2) {
      // position and send off second car
      // ...
    }
    car_event = 3 - car_event;  // alternate

EliasFrost

Thank you! That worked wonders! So that is how it's used, you learn something new every day. Thanks!

SMF spam blocked by CleanTalk