Applying a function to every room within a folder?

I'm working on a game where part is sort of open world with the player able to go through a set of rooms in any order but I'd like to have a script print part of a message in each room regardless of the order the player visits them. For organization I have all the rooms in this part of my game as objects under an empty room in the Quest editor, is there any way to give that parent folder/room a script that will apply when the player is in any of the rooms that are technically objects within that room?


I would just put it in the game.roomenter script (which runs whenever the player enters any room - found on the game's scripts tab).

Then you could use a check like:

if (Contains (Some_room, game.pov)) {

}

to determine if the room they're in is inside Some_room


Looks like that's working, thanks so much!


Aha! This is what I was asking about earlier when I said I was nesting more than one room in a single room and wanted to run an exit script for the bigger parent room (one without its own exits). I am just not really good at figuring out code, yet.
Could you clarify the above script for me? Is "Some_room" a word for the parent room's name or is "Some" the parent (of rooms) room name or is that something else?


In this script, I used Some_room as the name of the containing room.

In this case, I understood that notaroh wanted a script to run every time the player exits a room inside the container; whether they're leaving the containing room or moving between rooms within it. For your question, I interpreted your question as wanting to run a script only when the player leaves the containing room.


Yes, that's right. I just haven't had any luck yet, except
scripting one room at a time. I was a little afraid I was misreading your instructions, so I decided to just script the outer rooms.


Yes, you can give the parent folder/room a script that will apply when the player is in any of the rooms that are technically objects within that room. Here's how to do it:

Select the parent folder/room in the Quest editor.
Click on the "Scripts" tab.
Click on the "Add Script" button.
Select the "On enter" event from the dropdown menu.
Write the script code that you want to apply when the player enters any of the rooms within the parent folder/room.
Here's an example script code:
msg ("You are now in the open world section of the game. Explore at your leisure!") </function>

This code will display a message to the player every time they enter any of the rooms within the parent folder/room. You can customize the message to suit your needs.

Note that any script added to the parent folder/room will apply to all objects within it, so be careful not to add conflicting or redundant scripts to individual rooms within the parent folder/room.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums