Creating list of children objects

Ion_444
So I have clothing in my game, and I want there to be a description of the clothes a character's wearing whenever you look at them.

Normally, I'd do something like this (pseudo code follows):
--
For each child object in target character,

check if child object is a piece of clothing
if child object is clothing, check if it is worn
if child object is worn, print alias of said object.
--
Except I'm having difficulties iterating through a character object, since that object is not a list. How would I retrieve a list of an object's children objects so I can iterate through each one individually?

Or is there a more elegant solution to my problem that I'm not seeing?

HegemonKhan
links:

http://docs.textadventures.co.uk/quest/

http://docs.textadventures.co.uk/quest/ ... lists.html
http://docs.textadventures.co.uk/quest/ ... aries.html

http://docs.textadventures.co.uk/quest/scripts/
http://docs.textadventures.co.uk/quest/ ... reach.html

http://docs.textadventures.co.uk/quest/scopes.html

// specifically for your Player Objects only, as an alternative to using the 'getdirectchildren' and 'getallchildobjects' :
http://docs.textadventures.co.uk/quest/ ... ntory.html
http://docs.textadventures.co.uk/quest/ ... ntory.html

http://docs.textadventures.co.uk/quest/functions/ (categorical order)
http://docs.textadventures.co.uk/quest/ ... tions.html (alphabetical order)
http://docs.textadventures.co.uk/quest/ ... ldren.html
http://docs.textadventures.co.uk/quest/ ... jects.html
http://docs.textadventures.co.uk/quest/scopes.html

// the lazy way (lol):
http://docs.textadventures.co.uk/quest/ ... jects.html

---------

basically, the quest engine has already built-in ways to populate+get various Objectlist Attributes, and also Objects~Attributes within Objects (or other Elements within Elements), and once with an Objectlist Attribute, populated with the desired Objects, then you can use the built-in Functions~Scripts to iterate through the lists (and~or dictionaries) and do whatever you want with them.

also, quest's 'class~group' is known as an 'Object Type (Types)' and their use via Inherit Attributes, see here:

http://docs.textadventures.co.uk/quest/ ... /type.html
http://docs.textadventures.co.uk/quest/ ... types.html
http://docs.textadventures.co.uk/quest/ ... nced_.html (this mostly covers tabs and making types specifically for Pixie's 'Magic System + Simple Combat System' Library, so it's a bit, tangent~off topic or is too advanced+specific, as a link for about Object Types)
http://docs.textadventures.co.uk/quest/ ... types.html

-------

an example:

you got your 'clothing' Objects on~inside~added_to your 'player' Player Object

<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<attr name="chest" type="object">none_clothing</attr>
<attr name="waist" type="object">none_clothing</attr>
<attr name="left_hand" type="object">none_armor</attr>
<attr name="right_hand" type="object">none_weapon</attr>
<object name="none_clothing">
<inherit name="editor_object" />
<attr name="type_of_object" type="string">clothing</attr>
</object>
<object name="none_weapon">
<inherit name="editor_object" />
<attr name="type_of_object" type="string">weapon</attr>
</object>
<object name="none_armor">
<inherit name="editor_object" />
<attr name="type_of_object" type="string">armor</attr>
</object>
<object name="pants">
<inherit name="editor_object" />
<attr name="type_of_object" type="string">clothing</attr>
</object>
<object name="shirt">
<inherit name="editor_object" />
<attr name="type_of_object" type="string">clothing</attr>
</object>
<object name="sword">
<inherit name="editor_object" />
<attr name="type_of_object" type="string">weapon</attr>
</object>
<object name="shield">
<inherit name="editor_object" />
<attr name="type_of_object" type="string">armor</attr>
</object>
</object>

<function name="equip_clothing">
foreach (object_variable, GetDirectChildren(player)) {
if (HasString (object_variable, "type_of_object") and object_variable.type_of_object = "clothing") {
// etc equip scripting, I left out some needed Attributes, such as whether it is 'worn' and also Attributes to determine what body location for what Object Attribute to equip (assign) the Object to, lol, meh. This is just a brief simple example, not a full sample~functional equipment system, example, lol.
}
}
</function>


or, since this example is using a Player Object, you can also do this too:

foreach (object_variable, ScopeInventory()) { scripts }

The Pixie
The important part of HK's post is code that looks like this:
// create a list, then add to it the alias of each worn item
lst = NewStringList()
foreach (o, GetDirectChildren(character)) {
if (GetBoolean (o, "worn")) {
list add (lst, o.alias)
}
}
// output
if (listCount(lst) = 0) {
msg (character.alias + " is naked.")
}
else {
msg (character.alias + " is wearing " + Join(lst, ", ") + ".")
}

It assumes everything has an alias, which you imply in your OP, and is what I do, but may not be the case. It also assumes when an item is worn, an attribute (flag) called worn is set to true.

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

Support

Forums