How to variables: if x = 2, then y = 3

I want to automatically use the correct words for men and women.

The first passage asks “Do you have a girlfriend or boyfriend?”

If they choose girlfriend, then:

$girlfriend = “girlfriend”
$her = “her”
$she = “she”

If they choose boyfriend, then:

$girlfriend = “boyfriend”
$her = “his”
$she = “he”

This is how I do it in Python/C#. I can’t figure it out in Harlowe 3!

Using [Twine 2] [Harlowe 3]

Hi!

I have done something a little similar in one of my stories, though with a random choice of character gender. My code looks like this:

(set: $C1gender to (either: "woman", "man"))
(set: $C1pro to "She")
(set: $C1poss to "her")
(if: $C1gender is "man")[(set: $C1pro to "He") + (set: $C1poss to "his")]

So I used the (either:) macro to make the choice, but it sounds like you would want to allow the player to choose, probably by clicking a link?

But once you have done that, it is pretty easy to use (set:) and (if:) to assign your pronoun variables to the correct gender.

I hope that helps!

There is no need to add a mathematical “plus” symbol between the two (set:) macro calls within your (if:) macro’s associated Hook. That line should be just…

(if: $C1gender is "man")[(set: $C1pro to "He")(set: $C1poss to "his")]

…or like the following, if you use line-breaks & indentation to format your code…

(if: $C1gender is "man")[
	(set: $C1pro to "He")
	(set: $C1poss to "his")
]

note: if you are worried about the additional “blank lines” that formatting your code can add to the page , then use Collapsing whitespace markup to suppress them like so…

{
(set: $C1gender to (either: "woman", "man"))
(set: $C1pro to "She")
(set: $C1poss to "her")
(if: $C1gender is "man")[
	(set: $C1pro to "He")
	(set: $C1poss to "his")
]
}
1 Like

You use conditional macros like (if:) and (else:) to control which (set:) macros get called based on the current value of the variable you’re storing the end-user’s answer to your question.

note: You code example doesn’t include how you’re tracking the answer to the “girlfriend or boyfriend” question, so in the following example I will assume that answer has been assigned to the $girlfriend variable. I’m also going to assume that variable can only one of two values, those being “girlfriend” or “boyfriend”.

(if: $girlfriend is "girlfriend")[
	(set: $her to "her")
	(set: $she tp "she")
]
(else:)[
	(set: $her to "his")
	(set: $she to "he")
]

You can use (naked) Variable markup to inject the current value of those variables into textual content like so…

I see your $girlfriend over there, $she appears to be talking to $her friend Abcdef.

…or if you prefer to use the (print:) macro…

I see your (print: $girlfriend) over there, (print: $she) appears to be talking to (print: $her) friend Abcdef.

Thanks very much, as always I’ve learned a lot from your helpful comments! Cheers!