Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: myname on Thu 31/05/2012 01:58:13

Title: (Solved) Player enters room before speaking
Post by: myname on Thu 31/05/2012 01:58:13
I have my player give an inventory item to a npc and then walks to a door enters a new room and then speaks.  Unfortunately the player speaks before he enters the room out of order of the script.  Here is my scrip and thank you if you are able to help.


if (player.ActiveInventory == ibucket)

player.FaceCharacter(cJasper, eBlock); 
player.Walk(159, 147, eBlock);
cJasper.Say("Now that's a bucket St...hold on a second.");
cJasper.LockView(VIEW20);
cJasper.Animate(0, 7, eOnce);
cJasper.UnlockView();
cJasper.Think("Jaspa speakin...");
cJasper.Think("Oh my.  Well, I'll give ya a hand Geff.");
cJasper.LockView(VIEW22);
cJasper.Animate(0, 7, eOnce, eBlock, eForwards);
cJasper.UnlockView();
cJasper.Say("That boy is as useless as teats on a boar pig.");
player.Say("Don't care.  Get me out of here!...");
cJasper.Say("Take my clearance card, it will open any exit in the building and also the cash register at that Scrapple House on Conley Street.");
player.Say("Jasper you are a life saver.");
player.Say("Let me just grab my car keys and I'm outta here quicker than a greased up hog goin' down a waterslide.");
cJasper.Say("You go on boy.");
player.LoseInventory(ibucket);
cJasper.SetIdleView(7, 0);
player.Walk(181,118,eBlock);
player.ChangeRoom(5, 155, 165);
player.Say("Oh wonderful...Medawar.");
Title: Re: Player enters room before speaking
Post by: Khris on Thu 31/05/2012 02:12:47
Like is explained in the manual entry for Character.ChangeRoom (and lots of existing forum threads), that command is queued and only executed after the function finishes.
Depending on what else happens/already happened in room 5, the workaround can be as easy as putting the subsequent command(s) in that room's "first time player enters room" event.
If the player could have entered the room before, put the commands in the "after fadein" event and inside a check for either the previous room or a global variable.
Code (ags) Select
function room_AfterFadein() {
  if (player.PreviousRoom == 4) player.Say("Oh wonderful...Medawar.");
}
Title: Re: Player enters room before speaking
Post by: myname on Thu 31/05/2012 02:53:02
Wow, the "first time enter room" event was the most obvious solution.  I apologize. Thanks.