How to set weight in StoryCaption based on player's choice? (Twine)

Sorry if the title is worded weirdly, here’s what I’m trying to do:

I am making a twine game (Sugarcube), and at the start, I am letting the player choose their starting weight, money, etc using a listbox. Here is an example:

What is $name's weight? (Determines starting weight)
<<listbox "$weight" autoselect>>
	<<option "Slim">>
	<<option "Average" >>
	<<option "Chubby">>
	<<option "Large">>
	<<option "Obese">>
<</listbox>>

Each option has a different weight value. Depending on what the player chooses, the weight value of that option will be displayed on the StoryCaption.

For example, if Large is chosen, and the weight assigned to Large is 200, then I want the Weight counter in the StoryCaption to also show 200. But obviously, the weight will need to fluctuate as well later on, independent of the starting weight.

How could I get this to work?

1 Like

Well first of all, it may be more simple to use Links instead of a listbox for that case. For instance, assuming you want the next passage to pop up after the player selects a weight:

What is $name's weight? (Determines starting weight)

<<link "Slim">><<set $weight to XXX>><<goto "next passage's name">><</link>>

<<link "Average">><<set $weight to XXX>><<goto "next passage's name">><</link>>

<<link "Chubby">><<set $weight to XXX>><<goto "next passage's name">><</link>>

<<link "Large">><<set $weight to 200>><<goto "next passage's name">><</link>>

<<link "Obese">><<set $weight to XXX>><<goto "next passage's name">><</link>>

Simply replace the “XXX” with the number you want the player to weigh, and replace “next passage’s name” with the name of the passage you want the button to take the player to after selecting their weight.

Alternatively, if you want to use the listbox:

What is $name's weight? (Determines starting weight)
<<listbox "$weight" autoselect>>
	<<option "Slim" XXX>>
	<<option "Average" XXX>>
	<<option "Chubby" XXX>>
	<<option "Large" 200>>
	<<option "Obese" XXX>>
<</listbox>>

Later down the line, you can change the player’s weight with something along these lines:

To make the player gain weight: 
<<set $weight += X>>

To make the player lose weight:
<<set $weight -= X>>

X can be a number, or it can be randomized by being random(lowest number, highest number).

Some other helpful information can be found in the Twine Sugarcube Documentation here:
https://www.motoslave.net/sugarcube/2/docs/#introduction

Hope this information is of use.

4 Likes

Thanks for the help! I got it working now

1 Like