Getting All From Container

In my game, you use a locker room at one point. After changing, all your items are put in the locker.
I was wondering if there was a shortcut I could use to get everything at once, so the player didn't have to pick their items back up one at a time.

I tried using a command "get all/get all from locker" and the following script:

if (Locker65.isopen) {
foreach (item, AllObjects(Locker65)) {
item.parent = player
msg ("You take everything from the locker.")
}
}
else {
msg ("The locker is closed.")
}

However, I kept getting errors. Can I adjust this script to make it work, or is there a better way I could script this?


the 'AllObjects ()' has NO Parameter/Argument/Input, as it gets ALL the Objects in the ENTIRE game, and puts it into an Object List, which it then returns.

so, that's why you're getting an error. Otherwise, your code is (nearly) perfect.

take a look at the 'scopes', here: http://docs.textadventures.co.uk/quest/functions/#scope

you'd probably want to use the 'GetDirectChildren (XXX)' scope:

if (Locker65.isopen) {
  foreach (item, GetDirectChildren (Locker65)) {
    item.parent = player
  }
  msg ("You take everything from the locker.") // you want this here, so it's only shown/displayed/outputted once. You had it within the 'foreach' which would show/display/output it multiple times (equal to the quantity of items in the locker)
}
else {
  msg ("The locker is closed.")
}

an example of how the 'AllObjects ()' could/would be used:

creates/displays a numbered list of every single Object in the entire game

http://docs.textadventures.co.uk/quest/functions/corelibrary/displaylist.html (as an example within a Command)

<command name="example_command">
  <pattern>example</pattern>
  <script>
    DisplayList (AllObjects (), true)
  </script>
</command>

an example of manually coding in the same thing (just so you can see 'foreach' being used):

<command name="example_command">
  <pattern>example</pattern>
  <script>
    numbering_integer_variable = 0
    foreach (object_variable, AllObjects ()) {
      numbering_integer_variable = numbering_integer_variable + 1
      msg (numbering_integer_variable + ". " + object_variable.name)
    }
  </script>
</command>

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

Support

Forums