Game ignoring my Script

Started by metalmario991, Tue 24/02/2015 00:38:38

Previous topic - Next topic

metalmario991

This is the following script for an action in my game.

function hRed_Interact()
{
if (Power == 0)
{
Display("Nothing works without power.");
}
else if (Power == 1)
{
cEgo.Say("Maybe I shouldn't have pressed that...");
Display("You think?!?");
Wait(1);
cEgo.ChangeRoom(27, 900, 900);
Display("I hope I am in your will.");
cPod.ChangeView(15);
cPod.Animate(0, 5, eOnce, eBlock, eForwards);
Display("After blowing a big orfice in the side of the ship the pressure from space does a find job turning your already warped body into a hellish abomination. It is too sad and hideous to see.");
Display("(It's more hideous than your Mother-in-Law!)");
cEgo.ChangeRoom(11);
}
else if (Power == 2)
{
Display("There is no need for that.");
}
}

For some reason the game ignores cEgo.ChangeRoom(27, 900, 900);, displays the message afterwards, and then gets stuck on WAIT. What on Earth is Wrong here?

Snarky

Check out the AGS Manual entry on ChangeRoom(). The implication of that is that you can't really script chains of events that involve changing rooms in a single script.

monkey0506

If you need to run through a sequence of events that involve the player changing rooms, then what you'd generally do is create a global variable to keep track of what point you're at in the sequence. You can use on_event with the eEventEnterRoomBeforeFadein event to help keep track of this.

If you absolutely want to keep all the code for the sequence in a single script, I'd recommend creating separate functions for each room used in the sequence, and then call those from on_event or rep_ex as needed.

One final tip - you can effectively get an "Enter room (after fade-in)" event by doing:

Code: ags
bool afterFadein = false;

function OnEnterRoomAfterFadeinEvent()
{
  // do your after-fade in stuff here (blocking events are okay too!)
}

function on_event(EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein)
  {
    afterFadein = true;
  }
}

function repeatedly_execute()
{
  if ((afterFadein) && (IsInterfaceEnabled()))
  {
    afterFadein = false;
    OnEnterRoomAfterFadeinEvent();
  }
}

Snarky

But monkey... there already IS a "Player enters room (after fadein)" event.

monkey0506

Only in the room scripts. This was meant as a way of keeping everything in one (non-room) script.

SMF spam blocked by CleanTalk