Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: actaria on Sat 05/11/2022 09:53:50

Title: [Solved] ChangerRoom alternative ?
Post by: actaria on Sat 05/11/2022 09:53:50
Hello,

I am stil working on my keyboard GUI it works very well with good and wrong password.

So  i wanted to enhance it a little more with some animations on it.

I created a new room with some animated objects and i put the keyboard GUI over it and it looks pretty good.

The problem i have is that once correct or incorrect password has been typed he Player has to go back to the previous room in front of the door with the PNJ

The PNJ is talking to say "this is the good password" or "this is not the good password' then he close a little window on the door

but with the cChar1.ChangeRoom(18,3275, 1022); the text is displaying before the keyboard GUI is off as you can see in the video:


And i also get some object and frame error when i got back to the previous room.

I think i found the reason why in the manual:

IMPORTANT: For player character this command does not change the room immediately; instead, it will schedule the room change, and perform it only once your script function has finished
(This is to avoid problems with unloading the script while it is still running). This means that you should not use any other commands which rely on the new room (object positionings, and so on)after this command within the same function.


Is there another command than ChangeRoom without this limitation ?
Am i going the wrong way ?

Thanks a lot in advance for you help.
Title: Re: ChangerRoom alternative ?
Post by: Khris on Sat 05/11/2022 10:10:24
Anything you want to happen back in the room with the NPC has to go inside the room's after_fadein event / function.

Use a global variable to keep track of what's supposed to happen. You need three values (nothing / password good / password bad) so an int.
If the player entered the correct password, you do
  password_reaction = 1;
  player.ChangeRoom(18, 3275, 1022);

In the other room:
function room_AfterFadein() {
  if (password_reaction == 1) {
    // password good
    // ...
  }
  else if (password_reaction == -1) {
    // password bad
    // ...
  }

  password_reaction = 0;
}
Title: Re: ChangerRoom alternative ?
Post by: actaria on Sat 05/11/2022 10:48:11
Hello Khris,

Well as usual fantastic help it's perfectly working now  :) with your great solution.

This is another one i would have never been able to find by myseft to be honest.

Thank you so much for sharing your knowledge.

I think this time i am done with this keyboard :) so i went from a simple text box to a nice animated keyboard i can say that i am hapy now because of you

Have a great day.
Title: Re: [Solved] ChangerRoom alternative ?
Post by: Khris on Sat 05/11/2022 11:53:07
Great, you're welcome :)