Message with some conditions doesn't work [SOLVED]

Started by dark1981, Mon 06/05/2019 09:48:26

Previous topic - Next topic

dark1981

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?

Matti

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
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();

Khris

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
  if (HasPlayerBeenInRoom(3) && player.PreviousRoom == 4) ...

dark1981

Ok, I tried this and it works!

Room1:
Code: ags

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!

Khris

You can also use  Game.DoOnceOnly(unique_string)  for this:

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

dark1981

Quote from: Khris on Mon 06/05/2019 12:52:39
You can also use  Game.DoOnceOnly(unique_string)  for this:

Code: ags
  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 :)

SMF spam blocked by CleanTalk