Check for attribute in a group
SDude
26 Nov 2014, 06:39Hello,
I'm trying to figure out if it is possible to make a script check if an attribute is bigger than a specific amount. But so far I've only been able to set these checks on each object individually. So mayhaps someone knows if checking for an attribute for multiple objects is possible(It would be ideal if it was possible to do it on an object type)?
I'm trying to figure out if it is possible to make a script check if an attribute is bigger than a specific amount. But so far I've only been able to set these checks on each object individually. So mayhaps someone knows if checking for an attribute for multiple objects is possible(It would be ideal if it was possible to do it on an object type)?
HegemonKhan
26 Nov 2014, 07:19yep, look into the 'foreach' and~or 'for' Script Commands (and using lists and dictionaries, and the Scopes):
(though this stuff is quite a bit advanced, if you're new to coding or to quest's coding)
http://docs.textadventures.co.uk/quest/ ... reach.html (do for all~every~*EACH*)
http://docs.textadventures.co.uk/quest/scripts/for.html (do for specific range and by skipping interval)
http://docs.textadventures.co.uk/quest/ ... lists.html
http://docs.textadventures.co.uk/quest/ ... aries.html
the Scopes (scroll down to the 'S' category):
http://docs.textadventures.co.uk/quest/ ... tions.html
also the Scope-likes (the "A" category):
http://docs.textadventures.co.uk/quest/ ... tions.html
the 'Alls': AllObject, AllExits, AllCommands, AllTurnscripts
-------------
an example:
(increasing all of our 4 primary attributes by 5, such as when leveling up)
game.primary_attribute_stringlist = split ("strength;endurance;intelligence;mentality", ";")
foreach (attribute_x, game.primary_attribute_stringlist) {
-> player.attribute_x = player.attribute_x + 5
}
----------------
if you jsut mean to set the same attributes upon multiple Objects, then you'll want to use Object Types:
http://docs.textadventures.co.uk/quest/ ... /type.html
http://docs.textadventures.co.uk/quest/ ... types.html
http://docs.textadventures.co.uk/quest/ ... types.html
Objects hold Attributes and~or other Objects
Object Types hold Attributes
think of an Object Type (confusingly shortened to 'Type', which gets confused with other uses of the word: 'type', such as Attribute Types: <attr name="xxx" type="xxx">xxx</attr>, sighs) as a basket holding eggs (attributes), so instead of giving each of those eggs individually to each object, instead you can give the basket (Object Type: via as an Inherited Attribute) to each of those Objects.
for example:
(YUCK!)
VS, using Object Types:
(MUCH BETTER!)
-----------------------
or, lastly, do you mean you want to SUM UP the total of Attributes on~from multiple Objects ???
(such as in leveling up, applying gained attribute points to multiple party members, instead of just a single main character)
you can use the 'foreach~for' and~or Commands+Functions+Parameters to achieve this.
(though this stuff is quite a bit advanced, if you're new to coding or to quest's coding)
http://docs.textadventures.co.uk/quest/ ... reach.html (do for all~every~*EACH*)
http://docs.textadventures.co.uk/quest/scripts/for.html (do for specific range and by skipping interval)
http://docs.textadventures.co.uk/quest/ ... lists.html
http://docs.textadventures.co.uk/quest/ ... aries.html
the Scopes (scroll down to the 'S' category):
http://docs.textadventures.co.uk/quest/ ... tions.html
also the Scope-likes (the "A" category):
http://docs.textadventures.co.uk/quest/ ... tions.html
the 'Alls': AllObject, AllExits, AllCommands, AllTurnscripts
-------------
an example:
(increasing all of our 4 primary attributes by 5, such as when leveling up)
game.primary_attribute_stringlist = split ("strength;endurance;intelligence;mentality", ";")
foreach (attribute_x, game.primary_attribute_stringlist) {
-> player.attribute_x = player.attribute_x + 5
}
----------------
if you jsut mean to set the same attributes upon multiple Objects, then you'll want to use Object Types:
http://docs.textadventures.co.uk/quest/ ... /type.html
http://docs.textadventures.co.uk/quest/ ... types.html
http://docs.textadventures.co.uk/quest/ ... types.html
Objects hold Attributes and~or other Objects
Object Types hold Attributes
think of an Object Type (confusingly shortened to 'Type', which gets confused with other uses of the word: 'type', such as Attribute Types: <attr name="xxx" type="xxx">xxx</attr>, sighs) as a basket holding eggs (attributes), so instead of giving each of those eggs individually to each object, instead you can give the basket (Object Type: via as an Inherited Attribute) to each of those Objects.
for example:
(YUCK!)
<object name="orc1">
<inherit name="editor_object" />
<alias>orc</alias>
<attr name="strength" type="int">10</attr>
<attr name="endurance" type="int">10</attr>
<attr name="dexterity" type="int">10</attr>
<attr name="agility" type="int">10</attr>
<attr name="speed" type="int">10</attr>
<attr name="luck" type="int">10</attr>
<attr name="intelligence" type="int">10</attr>
<attr name="spirituality" type="int">10</attr>
<attr name="mentality" type="int">10</attr>
</object>
<object name="orc2">
<inherit name="editor_object" />
<alias>orc</alias>
<attr name="strength" type="int">10</attr>
<attr name="endurance" type="int">10</attr>
<attr name="dexterity" type="int">10</attr>
<attr name="agility" type="int">10</attr>
<attr name="speed" type="int">10</attr>
<attr name="luck" type="int">10</attr>
<attr name="intelligence" type="int">10</attr>
<attr name="spirituality" type="int">10</attr>
<attr name="mentality" type="int">10</attr>
</object>
<object name="orc3">
<inherit name="editor_object" />
<alias>orc</alias>
<attr name="strength" type="int">10</attr>
<attr name="endurance" type="int">10</attr>
<attr name="dexterity" type="int">10</attr>
<attr name="agility" type="int">10</attr>
<attr name="speed" type="int">10</attr>
<attr name="luck" type="int">10</attr>
<attr name="intelligence" type="int">10</attr>
<attr name="spirituality" type="int">10</attr>
<attr name="mentality" type="int">10</attr>
</object>
<object name="dragon1">
<inherit name="editor_object" />
<alias>dragon</alias>
<attr name="strength" type="int">100</attr>
<attr name="endurance" type="int">100</attr>
<attr name="dexterity" type="int">100</attr>
<attr name="agility" type="int">100</attr>
<attr name="speed" type="int">100</attr>
<attr name="luck" type="int">100</attr>
<attr name="intelligence" type="int">100</attr>
<attr name="spirituality" type="int">100</attr>
<attr name="mentality" type="int">100</attr>
</object>
<object name="dragon2">
<inherit name="editor_object" />
<alias>dragon</alias>
<attr name="strength" type="int">100</attr>
<attr name="endurance" type="int">100</attr>
<attr name="dexterity" type="int">100</attr>
<attr name="agility" type="int">100</attr>
<attr name="speed" type="int">100</attr>
<attr name="luck" type="int">100</attr>
<attr name="intelligence" type="int">100</attr>
<attr name="spirituality" type="int">100</attr>
<attr name="mentality" type="int">100</attr>
</object>
<object name="dragon3">
<inherit name="editor_object" />
<alias>dragon</alias>
<attr name="strength" type="int">100</attr>
<attr name="endurance" type="int">100</attr>
<attr name="dexterity" type="int">100</attr>
<attr name="agility" type="int">100</attr>
<attr name="speed" type="int">100</attr>
<attr name="luck" type="int">100</attr>
<attr name="intelligence" type="int">100</attr>
<attr name="spirituality" type="int">100</attr>
<attr name="mentality" type="int">100</attr>
</object>
VS, using Object Types:
(MUCH BETTER!)
<object name="orc1">
<inherit name="editor_object" />
<inherit name="orc_object_type" />
</object>
<object name="orc2">
<inherit name="editor_object" />
<inherit name="orc_object_type" />
</object>
<object name="orc3">
<inherit name="editor_object" />
<inherit name="orc_object_type" />
</object>
<object name="dragon1">
<inherit name="editor_object" />
<inherit name="dragon_object_type" />
</object>
<object name="dragon2">
<inherit name="editor_object" />
<inherit name="dragon_object_type" />
</object>
<object name="dragon3">
<inherit name="editor_object" />
<inherit name="dragon_object_type" />
</object>
<type name="orc_object_type">
<alias>orc</alias>
<attr name="strength" type="int">10</attr>
<attr name="endurance" type="int">10</attr>
<attr name="dexterity" type="int">10</attr>
<attr name="agility" type="int">10</attr>
<attr name="speed" type="int">10</attr>
<attr name="luck" type="int">10</attr>
<attr name="intelligence" type="int">10</attr>
<attr name="spirituality" type="int">10</attr>
<attr name="mentality" type="int">10</attr>
</type>
<type name="dragon_object_type">
<alias>dragon</alias>
<attr name="strength" type="int">100</attr>
<attr name="endurance" type="int">100</attr>
<attr name="dexterity" type="int">100</attr>
<attr name="agility" type="int">100</attr>
<attr name="speed" type="int">100</attr>
<attr name="luck" type="int">100</attr>
<attr name="intelligence" type="int">100</attr>
<attr name="spirituality" type="int">100</attr>
<attr name="mentality" type="int">100</attr>
</type>
-----------------------
or, lastly, do you mean you want to SUM UP the total of Attributes on~from multiple Objects ???
(such as in leveling up, applying gained attribute points to multiple party members, instead of just a single main character)
you can use the 'foreach~for' and~or Commands+Functions+Parameters to achieve this.
SDude
26 Nov 2014, 07:51Thank you for the reply and setting me on the right direction as well, since I was moving in a somewhat different direction while trying to find a solution to this specific problem. Time to play around with lists.
HegemonKhan
26 Nov 2014, 08:15for more complex uses of lists:
http://docs.textadventures.co.uk/quest/ ... omint.html (randomization)
+
http://docs.textadventures.co.uk/quest/ ... titem.html
+
http://docs.textadventures.co.uk/quest/ ... count.html
example, my 'explore' and 'travel' code:
(the coding is my initial attempt at it, so it's a bit more shoddy than if I were to do it again, understanding now the aspect, that I was having trouble with when I did this code, but it still works, and maybe it can help you, if you can understand and follow it, and if not, just ask and I'll try to help)
-------------------------------------------
and there's also the useful:
http://docs.textadventures.co.uk/quest/ ... tains.html
ask if you need any help.
http://docs.textadventures.co.uk/quest/ ... omint.html (randomization)
+
http://docs.textadventures.co.uk/quest/ ... titem.html
+
http://docs.textadventures.co.uk/quest/ ... count.html
example, my 'explore' and 'travel' code:
(the coding is my initial attempt at it, so it's a bit more shoddy than if I were to do it again, understanding now the aspect, that I was having trouble with when I did this code, but it still works, and maybe it can help you, if you can understand and follow it, and if not, just ask and I'll try to help)
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>eef801a1-4e6b-4b0a-bdbf-8f3ecfa8389c</gameid>
<version>1.0</version>
<firstpublished>2013</firstpublished>
<turns type="int">0</turns>
<statusattributes type="simplestringdictionary">turns=</statusattributes>
<start type="script">
msg ("Important Note:")
msg ("Type in: help")
</start>
</game>
<object name="homeland">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<object name="grassland">
<inherit name="editor_room" />
</object>
<object name="plains">
<inherit name="editor_room" />
</object>
<object name="desert">
<inherit name="editor_room" />
</object>
<object name="tundra">
<inherit name="editor_room" />
</object>
<object name="swampland">
<inherit name="editor_room" />
</object>
<object name="mountains">
<inherit name="editor_room" />
</object>
<object name="forest">
<inherit name="editor_room" />
</object>
<object name="wasteland">
<inherit name="editor_room" />
</object>
<object name="coastland">
<inherit name="editor_room" />
</object>
<object name="hills">
<inherit name="editor_room" />
</object>
<command name="help_command">
<pattern>help</pattern>
<script>
help_function
</script>
</command>
<command name="explore_command">
<pattern>explore</pattern>
<script>
explore_function
</script>
</command>
<command name="travel_command">
<pattern>travel</pattern>
<script>
travel_function
</script>
</command>
<object name="data_object">
<inherit name="editor_object" />
<travel_string_list type="simplestringlist">homeland</travel_string_list>
<homeland_events_string_list type="simplestringlist">grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery</homeland_events_string_list>
<homeland_events_script_dictionary type="scriptdictionary">
<item key="grassland_discovery">
list add (data_object.travel_string_list, "grassland")
msg ("You've discovered the grassland! Now, you can travel to the grassland and explore it!")
</item>
<item key="plains_discovery">
list add (data_object.travel_string_list, "plains")
msg ("You've discovered the plains! Now, you can travel to the plains and explore it!")
</item>
<item key="desert_discovery">
list add (data_object.travel_string_list, "desert")
msg ("You've discovered the desert! Now, you can travel to the desert and explore it!")
</item>
<item key="tundra_discovery">
list add (data_object.travel_string_list, "tundra")
msg ("You've discovered the tundra! Now, you can travel to the tundra and explore it!")
</item>
<item key="swampland_discovery">
list add (data_object.travel_string_list, "swampland")
msg ("You've discovered the swampland! Now, you can travel to the swampland and explore it!")
</item>
<item key="forest_discovery">
list add (data_object.travel_string_list, "forest")
msg ("You've discovered the forest! Now, you can travel to the forest and explore it!")
</item>
<item key="mountains_discovery">
list add (data_object.travel_string_list, "mountains")
msg ("You've discovered the mountains! Now, you can travel to the mountains and explore it!")
</item>
<item key="hills_discovery">
list add (data_object.travel_string_list, "hills")
msg ("You've discovered the hills! Now, you can travel to the hills and explore it!")
</item>
<item key="wasteland_discovery">
list add (data_object.travel_string_list, "wasteland")
msg ("You've discovered the wasteland! Now, you can travel to the wasteland and explore it!")
</item>
<item key="coastland_discovery">
list add (data_object.travel_string_list, "coastland")
msg ("You've discovered the coastland! Now, you can travel to the coastland and explore it!")
</item>
</homeland_events_script_dictionary>
</object>
<turnscript name="global_turnscript">
<enabled />
<script>
game.turns = game.turns + 1
</script>
</turnscript>
<function name="help_function">
msg ("Type 'explore' to explore your area.")
msg ("Type 'travel' to travel to different areas.")
</function>
<function name="explore_function"><![CDATA[
switch (game.pov.parent) {
case (homeland) {
result_1 = ListCount (data_object.homeland_events_string_list) - 1
if (result_1 >= 0) {
result_2 = StringListItem (data_object.homeland_events_string_list,GetRandomInt(0,result_1))
invoke (ScriptDictionaryItem (data_object.homeland_events_script_dictionary,result_2))
on ready {
foreach (item_x, split ("grassland_discovery;plains_discovery;desert_discovery;tundra_discovery;swampland_discovery;forest_discovery;mountains_discovery;hills_discovery;wasteland_discovery;coastland_discovery",";")) {
if (result_2 = item_x) {
list remove (data_object.homeland_events_string_list, result_2)
}
}
}
} else {
msg ("There seemingly is nothing left to explore in this area.")
}
}
}
]]></function>
<function name="travel_function">
show menu ("Where do you wish to travel?",data_object.travel_string_list,false) {
if (not game.pov.parent = GetObject (result)) {
game.pov.parent = GetObject (result)
} else {
msg ("You are already at this area.")
ask ("Try again?") {
if (result=true) {
travel_function
} else {
msg ("You realize that you need to discover a new area to travel to first, before you can travel to that place.")
}
}
}
}
</function>
</asl>
-------------------------------------------
and there's also the useful:
http://docs.textadventures.co.uk/quest/ ... tains.html
ask if you need any help.

jaynabonne
26 Nov 2014, 12:06The other key thing about types is that you don't have to limit yourself to data attributes. You can also have script attributes, which means you can have a script in the base type that is automatically available for all the objects that inherit from that type.
And note as well that the attributes in the type merely set initial values for the object (more or less - it's not technically correct, but it's conceptually close enough). So you can then set the attribute later on an object, and only that object's attribute will be changed.
And note as well that the attributes in the type merely set initial values for the object (more or less - it's not technically correct, but it's conceptually close enough). So you can then set the attribute later on an object, and only that object's attribute will be changed.