0 votes
by (2.3k points)
I'm trying to figure out a way for a player to select *only* two options from a list of about ten or so, which they then have as $skill4 and $skill6 etc.

I have my other character selection parts as presets, but this one will be more of a custom character creation.

1 Answer

0 votes
by (23.6k points)

I'd implement that like this:

<<nobr>>
<<set $choices to ["skill1","skill2","skill3","skill4","skill5","Skill6"]>>
<<set $skills to []>>

Choose two skills to proceed:<br>

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

<<capture _i>>
<<linkreplace "$choices[_i]">>
	<<set $skills.push($choices[_i])>>
	<<if $skills.length gte 2>><<goto "NextPassage">><</if>>
<</linkreplace>>
<</capture>>
<br>
<</for>>

<</nobr>>

 

by (2.3k points)

That one worked a treat thanks!

However I have one last thing about this, I have tried to duplicate it for a similar outcome with a 'Player Class' instead of skills.

Choose a Character Class

<<nobr>>
<<set $choices to [
"Class 1",
"Class 2",
"Class 3",
"etc",
"etc",
"etc",
]>>

<<set $pcClass to []>>

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

<<capture _i>>
<<linkreplace "$choices[_i]">>
	<<set $pcClass.classDescription.push($choices[_i])>>
	<<if $pcClass.classDescriptionlength gte 1>><<goto "...">><</if>>
<</linkreplace>>
<</capture>>
<br>
<</for>>
<</nobr>>

I have altered the code for one choice only correctly I think, but the following part I must have to match the inventory code:

$playerClass.classDescription

Is causing errors, saying it cannot read .push.

I'm not sure of the intricacies of this one, as normally the variable doesn't have the extra .classDescription on it.

What wizardry am I miscasting here?

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...