Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: dark1981 on Mon 06/05/2019 09:48:26

Title: Message with some conditions doesn't work [SOLVED]
Post by: dark1981 on Mon 06/05/2019 09:48:26
I tried several ways to get this, but they didn't work:

I have the following rooms, starting at room 1:

3
|
2
|
1 - 4

I need a text to be displayed (Display format and only once) when you goes from the room 4 to the room 1 but only if you have visited room 3.

I know that it sholud be easy, but a don't get it. I deleted all the code related, so I can't not show what I'm trying, sorry  :-[

Any clue?
Title: Re: Message with some conditions doesn't work
Post by: Matti on Mon 06/05/2019 10:11:49
In the room_FirstLoad() event of room 3 set a variable, e.g. bool room3_visited = true;

Then in room_AfterFadeIn() of room 1 make a condition like this:

Code (ags) Select
if (room3_visited && player.PreviousRoom == 4)
  //display message


If the message should appear in room 4, before the player enters room 1, then just use if (room3_visited) //display message before player.ChangeRoom();
Title: Re: Message with some conditions doesn't work
Post by: Khris on Mon 06/05/2019 10:22:59
Learning how to use global variables is obviously a good thing, but AGS in fact has a dedicated function for this (probably because the engine has to keep track because of First_Load() anyway):

Code (ags) Select
  if (HasPlayerBeenInRoom(3) && player.PreviousRoom == 4) ...
Title: Re: Message with some conditions doesn't work
Post by: dark1981 on Mon 06/05/2019 11:55:26
Ok, I tried this and it works!

Room1:

bool messagestage1 = true;

function room_AfterFadeIn()
{

if (HasPlayerBeenInRoom(3) && player.PreviousRoom == 4 && messagestage1 == true)
{
  Display ("The message to show.");
  messagestage1 = false;
}
}


Because I need the message to not be displayed every time the player crosses from 4 to 1.

Thank you to everyone, your answers guided me good!
Title: Re: Message with some conditions doesn't work [SOLVED]
Post by: Khris on Mon 06/05/2019 12:52:39
You can also use  Game.DoOnceOnly(unique_string)  for this:

Code (ags) Select
  if (HasPlayerBeenInRoom(3) && player.PreviousRoom == 4) {
    if (Game.DoOnceOnly("was in 3, entered from 4")) Display("The message to show.");
  }
Title: Re: Message with some conditions doesn't work [SOLVED]
Post by: dark1981 on Thu 09/05/2019 01:05:59
Quote from: Khris on Mon 06/05/2019 12:52:39
You can also use  Game.DoOnceOnly(unique_string)  for this:

Code (ags) Select
  if (HasPlayerBeenInRoom(3) && player.PreviousRoom == 4) {
    if (Game.DoOnceOnly("was in 3, entered from 4")) Display("The message to show.");
  }


Wow! It works and is more elegant! Thank you very much. There are a lot of "prefabricated" commands that I still do not know :)