0 votes
by (2.3k points)

To start I have set my player skills as follows:

<<set $pcSkills to {
meleeCombatant: "Melee Combatant",
brawling: "Brawling",
}>>

However when I come to want to print the skills as a generic list ie

Skills:

<ul>

$pcSkills []

</ul>

so that''Melee Combatant'', ''Brawling'' should appear.

Instead though [object Object] [] appears.

 

PS. You coders are geniuses at this I swear, you make it look so easy! LOL

1 Answer

0 votes
by (159k points)

You are assign an instance of a JavaScript Generic Object to your $pcSkills variable, this value consists of a set of Key / Value pairs. You see the [object Object] output when you try to display the variable's value via Naked Variable markup (or when you try using one of the <<print>> related macros) because the object isn't supplying the information required to do otherwise.

You want to only list the Values of the object and you can use the the 'value only' variation of the range based <<for>> macro to do that.

<<set $pcSkills to {
	meleeCombatant: "Melee Combatant",
	brawling: "Brawling",
}>>

<<for _skillValue range $pcSkills>>
	_skillValue
<</for>>

 

by (44.7k points)

If you want that formatted the way I think you want that formatted, you'd make this slight change:

Skills:
<<for _skillValue range $pcSkills>>\
* _skillValue
<</for>>

The "*" gives it a dot to the left.  If you change the "*" to "#" then there will be a number to the left, but because it's inside a loop, you'll have to modify the loop a bit to get it to display properly:

<<set _txt = "Skills:">><<for _skillValue range $pcSkills>>\
	<<set _txt += "\n# " + _skillValue>>
<</for>>_txt

(The "\n" inside the quotes means "new line".)

If the gap between items is too large, then you may want to add something like this to your Stylesheet section:

.passage ul {
	-webkit-margin-before: 0em;
	-webkit-margin-after: 0em;
}

Hope that helps!  :-)

by (2.3k points)
Many thanks!

You folks are really unsung heroes of the programming scene!

Incredible.
by (2.3k points)
edited by

One more thing.

I'm trying to get both a name and the numbers of my attributes 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>>
<</for>>_txt

 

And it displayed:

1. 71

2. 60.

3. 59.

So I tried this:

<<set $pcStats to {

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

}>>

But got variable errors. :(

...