Possible to reference an attribute from a string(list)?

TinFoilMkIV
29 May 2015, 19:16
Specifically I'm trying to build a list that contains a set of attributes and then reference them from this list.

For example, say we have a bunch of skill rankings, I'd like to be able to either reset or print their values using a list instead of having to manually enter the code for each individual attributes.

in psuedo code
player.skills = split(combat;firearms;swimming;farming;negotiation;etc, ;)

foreach (item, player.skills){
//reference attribute from the current list item
//print current attribute value
//reset attribute to a preset value
}

The Pixie
29 May 2015, 20:38
Like this:
GetInt(player, item)
set(player, item, 14)

TinFoilMkIV
29 May 2015, 20:41
hmm, not seeing 'set' in the documentation, can you link me to a page on it if there is one?

also what's the GetInt() for? I'm guessing to check whether you're allowed to set it as an int before attempting to do so, although you didn't actually have it check anything in that code.

EDIT: nevermind found the documentation

that solves the functional bit for most coding purposes, but what about displaying the info from the attributes off the list?

EDIT2.0: actually I spose I could use GetInt() or GetString() or whatever the attribute type is for that

let me see if I got this right, it should be something like

foreach (item, player.skills){
msg (item + " = " + GetAttribute (player, item))
set(player, item, 1)
}

HegemonKhan
30 May 2015, 04:16
the 'set' is under the 'scripts' (not the 'functions' ) category in the documentation:

http://docs.textadventures.co.uk/quest/scripts/ (scroll down, as it is alphabetical order)

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

-------

GetAttribute
GetString
GetInt
GetDouble
GetBoolean
etc etc etc

all the 'Gets' get that Object's Attribute's specific Value (it also does the 'Has' Functionality too, returning 'null' if that Object~Attribute~Value doesn't exist or doesn't match up in an 'if' string comparison expression).

------

yes, your code:

foreach (item, player.skills){
msg (item + " = " + GetAttribute (player, item))
set(player, item, 1)
}


is perfect, you got it.

----------

though for aesthetics, I myself prefer this:

msg (item + ": " + GetAttribute (game.pov, item))

// strength: 5

I'd use the 'caps~uppercase' code, so 'strength' would be 'Strength', but I'm too lazy to look it up.

---------------

(a lot of extra expansion code too, cause I'm bored, laughs)

<game name="xxx">
<start type="script">
foreach (integer_attribute_variable, global_data_object.primary_attribute_stringlist_attribute) {
if (not HasInt (game.pov.Integer_attribute_variable) or not GetInt (game.pov.integer_attribute_variable = 5) {
set (game.pov, integer_attribute_variable, 5)
msg (integer_attribute_variable + ": " + GetInt (game.pov, integer_attribute_variable))
}
}
</start>
</game>
<object name="global_data_object">
<attr name="primary_attribute_stringlist_attribute" type="simplestringlist">strength;endurance;dexterity;agility;speed;luck;intelligence;spirituality;mentality;perception;deception;personality;charisma;leadership;alignment</attr>
</object>
}


and (non-expanded ~ too tired~lazy now, lol)

<command name="character_information_command">
<pattern>info</pattern
<script>
ClearScreen
foreach (item, game.pov.skills){
msg (item + " = " + GetAttribute (game.pov, item))
}
wait {
ClearScreen
}
</script>
}