0 votes
asked by (120 points)

Hi, I'm kinda new at this.

I'm making character relationships in a game I'm working on, where if (as an example) $npcRelationship goes up, you're closer with the character and if $npcRelationship goes down, you're not.

I want the story to have moments where you have a radiobutton choice mid-passage; usually one positive one (that makes the $npcRelationship increase), a neutral one (no change to $npcRelationship), and a negative one (that makes $npcRelationship decrease).

I'm having trouble figuring out how to make the radiobutton variable translate to $npcRelationship. Here's what I've tried:

<<radiobutton "$npc1" "a">>"I really like you, too!"
<<radiobutton "$npc1" "b" checked>>(Say nothing, wait to hear more)
<<radiobutton "$npc1" "c">>"I don't feel the same way. It's not you it's me."
<<if "$npc1" == "a">><<set $npcRelationship = $npcRelationship + 1>>
<<elseif "$npc1" == "c">><<set $npcRelationship = $npcRelationship - 1>>


I'm not getting any error messages, but the $npcRelationship isn't changing when I load the next page, no matter which radiobutton I chose in testing.

What am I doing wrong? Thanks for your help.

1 Answer

0 votes
answered by (131k points)

...but the $npcRelationship isn't changing when I load the next page...

The contents of a Passage is processed just before it is shown to the Reader, and generally the only exceptions to this any content contained within the body of an interactive macro. (like a <<link>>)

So when your example was processed the value of your  $npc1 story variable is whatever you initialised that variable to (likely an empty space) before referencing it within the <<radiobutton>> macros, this means the <<if>> and <<elseif>> macros will react to whatever that value is at the time they were processed and these macros are not processed again when the referenced story variable changes.

Your issue can be simply solved by moving the <<if>> and <<elseif>> macros to the start of your nextpage Passage.

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.