Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KyriakosCH on Wed 01/11/2017 21:25:13

Title: Script to make rooms visited trigger an event
Post by: KyriakosCH on Wed 01/11/2017 21:25:13
Hi, I have a question about how one would go about doing this.

Namely i want an event to take place when the character has visited some rooms (5 in this case). The change taking place would allow him to go to some other rooms, while prior to that there would be a text noting that he doesn't yet feel like doing that (eg it is cold in some of them, etc).

I suppose it is easy to do, but i am not familiar with the int command, and tried to find a way using the built-in script help but didn't manage too... Any help? :)

PS: i don't really mind if after the rooms have been visited the change is something like giving an item (so as to -not very elegant-codewise, i know- tie having that item to allowing entrance to other rooms) but i just don't know how to build the first command to check for rooms visited at least once :)
Title: Re: Script to make rooms visited trigger an event
Post by: eri0o on Wed 01/11/2017 23:50:53
My idea would be using a global variable to store the information that you visited the room.

1 - using global var
the global variable is in Explore Project, and then right click in the table.
(http://futureflashbackgame.com/AGS_FORUM_RESOURCES/helping_topics/step1_globalvar.png)

2 - creating a global var
inside, create a boolean variable, select a name you will remember.
(http://futureflashbackgame.com/AGS_FORUM_RESOURCES/helping_topics/step2_globalvarvalue.png)

3 - Create event for room enter
Click on the three dots (...) either in enter room after fade-in or enter room before fade in.
Spoiler
(http://futureflashbackgame.com/AGS_FORUM_RESOURCES/helping_topics/step3_enterroom.png)
[close]

4 - setting the global variable
inside the function that opened, attribute true to the global boolean variable you created.
(http://futureflashbackgame.com/AGS_FORUM_RESOURCES/helping_topics/step4_atribute.png)

5 - add the check in the function
I don't know if you are using hotspot object or whatever, just click in the interact three dots (...) to go to the respective function.
Spoiler
(http://futureflashbackgame.com/AGS_FORUM_RESOURCES/helping_topics/step5_hotspot.png)
[close]

6 - write the if case
then you basically need to check if the variable is true (player has visited) or false (player didn't visited).
(http://futureflashbackgame.com/AGS_FORUM_RESOURCES/helping_topics/step6_ifcondition.png)
Title: Re: Script to make rooms visited trigger an event
Post by: Crimson Wizard on Thu 02/11/2017 00:19:22
There is already HasPlayerBeenInRoom (http://www.adventuregamestudio.co.uk/wiki/Room_functions#HasPlayerBeenInRoom) function that checks that.

It does not work on rooms that does not save state (number 300+), in which case your would need to actually use global variables, I guess.
Title: Re: Script to make rooms visited trigger an event
Post by: KyriakosCH on Thu 02/11/2017 03:31:37
Thank you both :D

Since the trigger will be the player having visited all the first five rooms (eg 1,2,3,4,5) i guess i could use the global variable (or five of them)... :)

I suppose - in this case - i am defining the variable(s) with the hasplayervisited etc command?

I don't know of any case where i could use multiple commands in an 'if' line. Iirc there used to be an 'and' line too in the past?
Title: Re: Script to make rooms visited trigger an event
Post by: Gurok on Thu 02/11/2017 05:22:27
KyriakosCH, you use && to combine conditions with an 'and' in an if statement.

Combining Crimson Wizard's suggestion and your notes, you want something like this:

function hDoor_Interact()
{
    if(HasPlayerBeenInRoom(1) && HasPlayerBeenInRoom(2) && HasPlayerBeenInRoom(3) && HasPlayerBeenInRoom(4) && HasPlayerBeenInRoom(5))
    {
        player.ChangeRoom(6); // Or the room of your choice
    }
    else
    {
        Display("I don't feel like doing that.");
    }
}
Title: Re: Script to make rooms visited trigger an event
Post by: Crimson Wizard on Thu 02/11/2017 08:56:51
Hmm, there is another alternative, and I cannot immediately tell if that will be more convenient; depends on overall situation and future plans, I guess.
You may have only 1 global variable of type "integer" which you use as a counter. For example, called "stage1_rooms_visited".

Then, instead of assigning "true" to it, you instead increase the counter, but you need to put this specifically in "First time enters room" event of each room:
Code (ags) Select

function room_FirstLoad()
{
    stage1_rooms_visited++;
}


And when you want to check it:
Code (ags) Select

function hDoor_Interact()
{
    if (stage1_rooms_visited == 5)
    {
        // do something
    }
}


Title: Re: Script to make rooms visited trigger an event
Post by: KyriakosCH on Thu 02/11/2017 16:28:49
Thank you both, again!

And i suspected the && thing... but it really is a game-changer ( := ) for me! Highly useful addition to the if/else commands! :)

While prior to learning of the && option i was indeed Exactly looking for what Crimson_Wizard wrote above, i will now use the if &&, cause it allows for even leaving some lesser/not important room out :)