0 votes
by (2.3k points)

I'm trying to get both a name and the numbers of my list of data to display in the inventory.

Using the above method I can get the numbers to list, but not the actual sub-variable name.

As an example my variable is like this:


<<set $pcStats to {

str: 71,
agi: 60,
int: 59,


and my StoryCaption code is like this:

<<set _txt = "Attributes:">><<for _skillValue range $pcStats>>\
	<<set _txt += "\n# " + _skillValue>>

 Yet it displayed:

1. 71

2. 60.

3. 59.

So I tried this:

<<set $pcStats to {

str: "Strength" 71,
agi: "Agility" 60,
int: "Intelligence" 59,


Hoping the inventory would display:

Strength  71
Agility  60
Intelligence  59

But got variable errors. :(

1 Answer

+1 vote
by (44.7k points)

You just need to display the key for each value:

<<set _txt = "Attributes:">><<for _skill, _skillValue range $pcStats>>\
	<<set _txt += "\n# " + _skill + ": " +_skillValue>>

That will set _skill equal to the key for each key-value pair in the $pcStats object.  Note that objects are unordered lists, so the order you get in one browser may be different than the order you get in a different browser.

Also, this:

str: "Strength" 71

didn't work because the value you're trying to set on the key property isn't valid.  However, you could have done this instead:

str: "Strength " + 71

That would turn the value into a single string, instead of being a string value and a number value as you had previously.

Enjoy!  :-)

by (2.3k points)

Oh I see, thanks.

Ok I just did that and it displayed:

Strength: Strength = 51
Agility: Agility = 62
Intelligence: Intelligence = 64


by (23.6k points)
It works perfectly fine on my end and I have no idea what you could have possibly done to get the result you're getting unless you for some reason set $pcStats.str to "Strength = 71".
by (2.3k points)
Sorry, the numbers are fine, it's the issue of it displaying the same word twice.
by (23.6k points)

That's what I'm talking about. The only way I can think of how the "Strength ="  etc. would get mixed in there is if you incorrectly set your properties to strings. Try a few math operations:

<<set $pcStats.str += 2>>$pcStats.str

And see if your math works out fine.

by (2.3k points)
edited by
Alright, I got it working after some more trial and error. Thanks for the suggestions, very helpful and got me to where I want it to be I think.