Replacing a variable?

Hi! I’m a total newbie using Twine 2.5.1, Harlowe 3.3.3

In the story I’m creating, I want the player to first choose a name (which I managed). Later on, they get asked for the name, and they can either lie or tell the truth. If they lie, they have to come up with a fake name. The other characters will then refer to the player’s character with that fake name until the truth eventually comes up.

My problem is, I have no idea how to go at this since the player doesn’t have to lie; they might as well tell the truth and use the real name for the whole game. I will also need to be able to revert back to using the real name at some point, which is the issue here, since otherwise I could just replace the original $name with the new fake name. I seriously don’t think going…

(if:$fakename is true)[Hey, $fakename!]
(if:$fakename is false)[Hey, $name!]

…for the whole story is the only or optimal way to go at this, but after a long time of searching for an answer, I still have no idea how to do this. I’ve tried using macros like “replace” (among other things) but none of it seems to work.

A lot of the stuff that goes past pure basics is still very confusing to me so I do apologize for a possibly simple question. I swear I tried to get it work on my own before coming to take your time :smiley:

I’d appreciate even a nudge in the right direction. Thank you so much in advance!

People are often known by something other than their legal name, and that other name can be often be referred to as “known as” or “alias”.

So you use two variables to track the character’s name and alias, then at the start of the project those two variables can be initialised to the same value. Such initialising is generally done within your project’s startup tagged Passage.

(set: $name to "Jane")
(set: $alias to "Jane")

…and anytime you want to show the person’s name you would use the $alias variable…

Hello $alias, how are you.

At the point in your project where you allow the Reader to “chose” the name of the character you would need to update both variables. As you didn’t supply an example of the code you are using to allow the Reader to “chose” a name the following code will assume the value supplied by the Reader was stored in a temporary variable named _input, and that the cleaning & validation of that supploed value has already occurred.

(set: $name to _input)
(set: $alias to _input)

Now when the Character lies about their name you simply update the $alias variable…

Who are you?
{
|choice>[
	(link: "Lie")[
		(set: $alias to "John")
		(hide: ?choice)
		(show: ?answer)
	]
	<br>
	(link: "Be truthful")[
		(hide: ?choice)
		(show: ?answer)
	]
]
|answer)[My name is $alias]
}

You can tell if the Character lied by comparing the current values of the two variables.

(if: $alias is $name)[I'm glad you didn't lie about your name]

or

(if: $alias is not $name)[Why did you lie to me?]

And when it comes time for the Character to confess what their real name is simply update the value of the $alias variable…

While you have known me as $alias up until now, (set: $alias to $name) my real name is $alias !

Thank you so much! I immediately got it to work. Can’t believe the answer was so simple.

Also, as a sidenote: on my googling adventures, I’ve found a lot of your older answers to people, and they’ve all been an enormous help. So thank you for all you do!

1 Like