[Solved] ChangerRoom alternative ?

Started by actaria, Sat 05/11/2022 09:53:50

Previous topic - Next topic

actaria

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.

Khris

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
Code: ags
  password_reaction = 1;
  player.ChangeRoom(18, 3275, 1022);

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

  password_reaction = 0;
}

actaria

#2
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.

Khris


SMF spam blocked by CleanTalk