Script to make rooms visited trigger an event

Started by KyriakosCH, Wed 01/11/2017 21:25:13

Previous topic - Next topic

KyriakosCH

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 :)
This is the Way - A dark allegory. My Twitter!  My Youtube!

eri0o

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.


2 - creating a global var
inside, create a boolean variable, select a name you will remember.


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
[close]

4 - setting the global variable
inside the function that opened, attribute true to the global boolean variable you created.


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
[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).

Crimson Wizard

#2
There is already 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.

KyriakosCH

#3
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?
This is the Way - A dark allegory. My Twitter!  My Youtube!

Gurok

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:

Code: ags
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.");
    }
}
[img]http://7d4iqnx.gif;rWRLUuw.gi

Crimson Wizard

#5
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

function room_FirstLoad()
{
    stage1_rooms_visited++;
}


And when you want to check it:
Code: ags

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



KyriakosCH

#6
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 :)
This is the Way - A dark allegory. My Twitter!  My Youtube!

SMF spam blocked by CleanTalk