0 votes
by (310 points)
edited by
In this case, the player is choosing a fantasy race, which I want to change one of their attributes.  At first, I was going to use if/else, but when I checked that, I learned it had to be Boolean, and I couldn't just use set to change the variable.  I've tried unsuccessfully to use a couple things, but I'm not getting anywhere.

Advise or suggestions?

Edit:  I hope this doesn't come off as snarky, but after reading the first answer, I thought I'd put a clarification:  I know that "if/else" statements can't be used in conjunction with "set" statements.  I'm trying to get a player to input a fantasy race which will cause a change to a numerical value.  So if they choose "elf" the value of the player's dexterity increase by 2.

Sorry, if that seems snarky.

2 Answers

0 votes
by (63.1k points)
edited by

The expression has to yield a boolean value, and that's it. 

You can use comparison operators, like is, >, <, >=, <=, contains, etc to compare two values or variables and get a boolean. 

(if: $race is 'elf')[
    You're an elf! 
    You're not an elf. 

While it's true that (if:) only accepts boolean values, like in most programming languages, it can evaluate an expression to get to that value. 

+1 vote
by (159k points)

Please use the Question Tags to state the name and full version number of the Story Format you are using, as it helps with filtering & searching. Adding this information to the Question Title is of little benefit.

You didn't supply an example of how you are initialising your current player variable nor how you place to track their dexterity, and there are a number of different ways this could be done (distinct variables for each attribute; a single Data-Map containing all the attributes, etc...). I'm guessing you may be using the second option so I have used that in my solution.

1. Initialise your player related attributes within your protect's startup tagged special passage.

(set: $player to (dm:
	"Name", "Abcde",
	"Race", "Uknown",
	"Dexterity", 0

2. Add TwineScript like the following to the Passage containing the Race selection. It displays the current values of each of the player's attributes and then uses a (link:) macro to allow the Reader to select which race the player is (1).
I have also included an example of how to use a (replace:) macro combined with a named hook to refresh the currently displayed attributes information.

Name: (print: $player's "Name")
Race: [(print: $player's "Race")]<race|
Dexterity: [(print: $player's "Dexterity")]<dexterity|

Select a race for the player: {
	(link: "Elf")[
		(set: $player's "Race" to "Elf")
		(set: $player's "Dexterity" to it + 2)
		(replace: ?race)[(print: $player's "Race")]
		(replace: ?dexterity)[(print: $player's "Dexterity")]

(1) I have only implemented the "Elf" link but you should be able to use it as a guide you adding other races to the selection.