Avoid conflicting action error?

Started by Surplusguy, Sat 28/09/2013 00:38:21

Previous topic - Next topic

Surplusguy

So I've set up a minigame to run like this. Several objects fly at the player, who must click on them to make them stop moving.
Once all the objects are hit, a rep_exec variable makes the player move to the next room. If the player is hit, they move to a
"game over" screen. The problem is, if the player is hit while they are about to move to the next room, an error occurs where both can't be executed at once, of course. What I want to know is, besides making the objects disappear instantly when hit, is there a way to avoid this error?

Cheers, Surplus
GHRPLTSM

Khris

The error you're getting is because your code allows both conditions (win & lose) to be true in the same frame.
You can avoid this by not calling player.ChangeRoom() directly when the win or lose condition is met:

Code: ags
  // in repeatedly_execute (pseudo code)
  int next_room = 0;
  if (player loses) next_room = 3;
  if (player wins) next_room = 4; // winning takes precedence
  if (next_room) player.ChangeRoom(next_room);


That way you can't end up with two room changes in the queue.

Surplusguy

And I thought I could get out of some extra work by not setting up two separate variables for the actions... Oh well.

Thanks for the help, Khris!
GHRPLTSM

Khris

Wait, how are you setting up two separate variables? My code doesn't.

SMF spam blocked by CleanTalk