Variable Macro Conundrum

Twine Version: 2.3.5
Story Format: 2.30

I have this as my pre-set character

<<set $pcSkills to {

spotHidden: "Spot Hidden",
}>>

And it works great for this:

You open draws and scatter items about as you try to find notes, clues or documents that may reveal secrets about the deadly duo who attacked you.
<<nobr>>
<<if $pcSkills.spotHidden>>Your sharp eye misses nothing.

<<else>>You find nothing.<</if>>

I have this in the custom character creation passage via mouse clicking on selections:

Choose 2 Skills from the list:

<<nobr>>

<<set $choices1 to [
"Marksmanship",
"Spot Hidden",
"Charm",
]>>

<<set $pcSkills to []>>

<<for _i to 0; _i lt $choices1.length; _i++>>

<<capture _i>>
<<linkreplace "$choices1[_i]">>
	<<set $pcSkills.push($choices1[_i])>>
	<<if $pcSkills.length gte 2>><<goto "Custom Character Creation 3">><</if>>
<</linkreplace>>
<</capture>>
<br>
<</for>>

<</nobr>>

On the next screen I have to show it’s been selected:

You are skilled in:

@@.skill;''<<for _skillValue range $pcSkills>>
_skillValue
<</for>>''@@

Great!

So with this done later in the story I want to have some text and stuff to appear IF the character has say ‘Marksmanship’ or ‘Spot Hidden’ as it did before with the preset character.

What would I do to make this:

You open draws and scatter items about as you try to find notes, clues or documents that may reveal secrets about the deadly duo who attacked you.
<<nobr>>
<<if $pcSkills.spotHidden>>Your sharp eye misses nothing.

<<else>>You find nothing.<</if>>

Work yet keep the clickable selection? Or am I SOL with this whole thing?

Maybe this (completely untested)?

Choose 2 Skills from the list:

<<nobr>>

<<set $choices1 to [
{name: "marksmanship", text: "Marksmanship"},
{name: "spotHidden", text: "Spot Hidden"},
{name: "charm", text: "Charm"},
]>>

<<set $pcSkills to {}>>

<<for _i to 0; _i lt $choices1.length; _i++>>

<<capture _i>>
<<linkreplace "$choices1[_i]">>
	<<set $pcSkills[$choices1[_i].name] to $choices1[_i].text>>
	<<if Object.keys($pcSkills).length gte 2>><<goto "Custom Character Creation 3">><</if>>
<</linkreplace>>
<</capture>>
<br>
<</for>>

<</nobr>>

Each choice is an object with the property name and the text, $pcSkills is an object instead of an array (so it has named properties instead of numbered ones), and then you have to use Object.keys to get a list of keys so you can find out how many you’ve set.

Hopefully I didn’t miss anything or make some completely avoidable mistakes there…

1 Like

Thanks, but It didn’t work.

Just kept letting me choose options until none were left unfortunately.

EDIT!

It just did ‘work’, and functioned perfectly in the actual passages with the $spotHidden variable in it.

Unfortunately the option names in the custom creation passage displayed:

[object OBJECT]
[object OBJECT]
[object OBJECT]

Instead of:

Marksmanship
Spot Hidden
Charm

@HiEv
@JoshGrams

Not sure if this is a way out?

Change
<<linkreplace "$choices1[_i]">>
to
<<linkreplace $choices1[_i].text>>

2 Likes

Worked brilliantly. Thanks a lot for that, it really finished off the whole thing. Was about to abandon the custom character creation part until you chimed in.

Thanks again! :slight_smile: