Login
Remember
IF Answers
Ask a Question

# Is there an expression or script that addresses an attribute that is shared by all objects in a room (or the game)?

0 votes
338 views
asked Apr 1 in Authoring by Nimrod
recategorized Apr 1 by Alex

In detail, all objects I have in my game have a "real" or "present"-attribute and I would like it if the player leaves a room, those attributes of the objects in the room would be set to "false". Is that possible and if yes, how?

- quest

## 1 Answer

+1 vote
answered Apr 1 by The Pixie (121 points)

I would set up a script to fire when the player enters a room (unfortunately there is no equivalent when leaving a room). Go to the Script tab of the game object, and look for "Script when entering a room". Click the seventh icon, Code view, and paste this in:

      foreach (o, AllObjects()) {
        o.real = false
        o.present = false
      }

Note that this will set both the values for every object (even rooms) each time; I am guessing that will do. If objects have either "real" OR "present", you would have to test which was there first

commented Apr 1 by hegemonkhan (161 points)
edited Apr 1 by hegemonkhan
it can be anything you want, it's just a 'placeholder variable'.
foreach (placeholder_variable, Object_name.Attribute_name) {
// script(s) using 'placeholder_variable'
}
<type name="character_object_type">
<attr name="run_laps" type="script">
msg (this.name + " runs laps.")
<attr>
</type>
<object name="joe">
<inherit name="editor_object" />
<inherit name="character_object_type" />
</object>
<object name="jill">
<inherit name="editor_object" />
<inherit name="character_object_type" />
</object>
<object name="jim">
<inherit name="editor_object" />
<inherit name="character_object_type" />
</object>
game.team = split ("joe;jill;jim", ";")
foreach (team_member, game.team) {
do (team_member, "run_laps")
// outputs: Joe runs laps.
// outputs: Jill runs laps.
// outputs: Jim runs laps.
}
foreach (x, game.team) {
do (x, "run_laps")
// outputs: Joe runs laps.
// outputs: Jill runs laps.
// outputs: Jim runs laps.
}
foreach (item, game.team) {
do (item, "run_laps")
// outputs: Joe runs laps.
// outputs: Jill runs laps.
// outputs: Jim runs laps.
}
foreach (blahblahblah, game.team) {
do (blahblahblah, "run_laps")
// outputs: Joe runs laps.
// outputs: Jill runs laps.
// outputs: Jim runs laps.
}
also, if you want help on using Lists+Dictionaries (which 'foreach' and 'for' are used for), I wrote this guide:
http://forum.textadventures.co.uk/viewtopic.php?f=18&t=5137
ask if you got any other questions, or need help with anything.

## Related questions

- Is there a limit to the length of a script in Quest?
- Is there syntax to allow multiple expressions in the same script?
- In a Gamebook, how do I fix that the text processor is not working properly on my version of Quest (I think)?
- Quest - Is there to "ScopeInventory" or "ScopeReachableInventory" that includes not visible items?
- With Flexible Windows by Jon Ingold, is there a way to make the text display at the top of the window, even in Gargoyle? (Inform 7)

...