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?

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.
This site is now closed.
As of 1st November 2015, this site is a read-only archive. For more information see the intfiction forum post

Welcome to IF Answers, a site for questions and answers about Interactive Fiction.

Technical questions about interactive fiction development tools such as Inform, Twine, Quest, QuestKit, Squiffy, Adrift, TADS etc. are all on-topic here.

Non-technical questions about interactive fiction are also on-topic. These questions could be about general IF design, specific games, entering the IF Comp etc.
...