Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: metalmario991 on Tue 24/02/2015 00:38:38

Title: Game ignoring my Script
Post by: metalmario991 on Tue 24/02/2015 00:38:38
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?
Title: Re: Game ignoring my Script
Post by: Snarky on Tue 24/02/2015 01:25:15
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.
Title: Re: Game ignoring my Script
Post by: monkey0506 on Tue 24/02/2015 06:24:19
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) Select
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();
  }
}
Title: Re: Game ignoring my Script
Post by: Snarky on Tue 24/02/2015 09:19:41
But monkey... there already IS a "Player enters room (after fadein)" event.
Title: Re: Game ignoring my Script
Post by: monkey0506 on Tue 24/02/2015 13:20:05
Only in the room scripts. This was meant as a way of keeping everything in one (non-room) script.