Problem concerning choice and consequence

Hi! I feel like I’ve learned a lot about working with choicescript; I’ve read up on a lot of stuff here in the forum as well as on the wiki, but there is one issue that I haven’t found a solution for yet.

When the reader/player makes a choice, and the result of that choice can be read directly in the following scenes - no questions there. But when, for example, you want a variable to affect stuff later on in the story, like a scene five chapters later, how do you manage that?

From what I’ve come to understand, the *if command is the one you use for those kinds of scenes, right? But whenever I try it, my game doesn’t seem to want to register it. My question is: Am I using the wrong command, or maybe just writing it out in the wrong way? Thanks in advance!

Say you create this variable in startup:
*create killed_bandits false
Then, after you choose to kill the bandits:
*set killed_bandits true
For a check, you do just use:
*if killed_bandits
Or
*if killed_bandits = true

Yep.

On a scene

*set superimportantstatalteryourending 999

And 199 chapters later

*if superimportantstatalteryourending = 999
asdfasdfasdf

Thanks to both of you! That clears a lot of things up :slight_smile:

Okay, so I tested out the code you posted, and it worked without problem.

But there is a scene when I want the player to be able to lie to a character about their name, which doesn’t seem to work the same way.

This is what the code looks like:

*choice
#Tell him my true name.

	“I'm ${name}",I say. "${name} ${surname}."
	
	"${name}, huh? I like it", he says, leaning against the sofa. 
	*goto_scene chapt1michexplain
	
#Lie about my name.
	*goto_scene fulsenameinput

*label fulsename

*choice
#What should I tell him my first name is?
*input_text fulsename

*label fulsesurname

*choice
#And what should I tell him my surname is?
*input_text fulsesurname

	*goto_scene liename

“I’m {fulsename}", I lie. "{fulsename} ${fulsesurname}.”

“${fulsename}? I like it”, he says, leaning against the sofa.
*goto_scene chapt1michexplain

It works if you lie in the upcoming scene, but when I try to implement it later as a variable, when the character says either your true name or the false name you told him, it doesn’t work. Either I’m told that “fulsename” is not a variable, or if I try to make it one and set it to “true”, the false name just becomes “true”. Any ideas how to solve this? Thanks!

Are fulsename and fulsesurname *temp variables? If so they will disappear when you change scene.

They need to be *create variables in the startup.txt scene.

No, they are not temp variables; they are created in the startup file.

Can you post the part of the code when you are trying to use these variables and they don’t work?

You wrote {fulsename} and not ${fulsename}, btw.
The dollar sign $ is important.

That’s what I keep telling myself when I am too lazy to work.
:thinking:

2 Likes

It’s for the muhney! :money_mouth_face:

Seriously though, would the absence of that sign cause the game to recognize the variable as non-existent? I did ignore it because I thought it wasn’t related.

No, it would simply write {fulsename} in the screen.

${var} means, “Hey code, write out whatever text inside the {var}!”
While {var} means, “Code, can you do this to whomever inside the {var}?”

Therefore, *set {var} is valid while *set ${var} isn’t.

The same can be said in normal “passage code” for the opposite:

Lorem ipsum {var} dolor sit amet
Lorem ipsum ${var} dolor sit amet

These guys produce 2 different texts.

I was confused about that, not knowing why it’d be the cause of the issue, thanks.

My attention was directed here. So, come to think of it, I see no problems as to why this dollar sign would cause the variable to be non-existent, though, it’s good you mentioned. (Since I doubt the author wanted {fulsename} displayed).

Huh, that’s weird; in my notepad++ text, the dollar signs are there. Something must have happened when I copied it :confused:

But no, that’s not really related, as that scene is the one that comes right after you lie about your name and it works for that scene. It’s the scenes that comes after, when I want the name variable to change depending on whether you lied or told the truth, that doesn’t work.

But from what I can gather, I’m supposed to use *set {fulsename} = true, or something similar, after the player has chosen to lie? When I tried it like this:

*set fulsename = true,

it didn’t work, so maybe that’s the issue. I’m going to try it out at least!

No, that cannot be done because fulsename is a string variable, one that contains text. To use true or false you would need a boolean variable.

You should do a (*create fulsename_used false) in your startup.txt. This will be the variable to identify if the player used a false name or not. Use a (*set fulsename_used true) in the choice where the false name can be used by the player.

So later in the game if you want to check if the false name was used by the player, you would type:

*if (fulsename_used = true)
    Whatever to happen when the player uses the false name
*else
    Whatever to happen if the player did not use a false name

You can also use multireplace, as explained here in the wiki, to quickly create something that will display either the false name or the real name.

@{fulsename_used My name is ${fulsename} ${fulsesurname}|My name is ${name} ${surname}}.

This will display either the real name or the false name in the screen depending if the player used a false name or not.

Thanks a lot! I tried it out, but the character still refers to the player as “true”.

*choice
#What should I tell him my first name is?
*input_text fulsename_used

*label fulsesurname_used

*choice
#And what should I tell him my surname is?
*input_text fulsesurname_used

	*goto_scene liename

And then

“I’m {fulsename_used}", I lie. "{fulsename_used} ${fulsesurname_used}.”
*set fulsename_used true
*set fulsesurname_used true

“${fulsename_used}? I like it”, he says, leaning against the sofa.

*goto_scene chapt1michexplain

In this last scene, the character calls the player “true”. I assume I’ve got something wrong, although I followed what you had written. I’m not very code savvy :confused:

You need to do it like this, just add the (*set fulsename_used true) in the choice where the player uses the fake name. There is no need to create two, one for name and surname, just one will suffice, as you will not place the text inside them, but just use them to flag if a fake name was used or not.

*choice
#Tell him my true name.

	“I'm ${name}",I say. "${name} ${surname}."
	
	"${name}, huh? I like it", he says, leaning against the sofa. 
	*goto_scene chapt1michexplain
	
#Lie about my name.
	*set fulsename_used true ****The use of the boolean variable goes here. When the player chooses to use a false name, this variable will be set to true.****
	*goto_scene fulsenameinput

*label fulsename

*choice
#What should I tell him my first name is?
*input_text fulsename

*label fulsesurname

*choice
#And what should I tell him my surname is?
*input_text fulsesurname

	*goto_scene liename

The _used one you will just use for checks, to know that the player has used the false name and not the real name; you don’t assign any value to the fulsename_used besides true or false. And also, the true and false in this case make sure not to use quotes around it (like “true”, use just true instead).

You will use the _used variable just to do something in case the player selected a false name.

*if (fulsename_used = true)
    “I’m ${fulsename}", I lie. "${fulsename} ${fulsesurname}.”

    “${fulsename}? I like it”, he says, leaning against the sofa.
    *goto_scene chapt1michexplain
*else
    “I’m ${name}", I tell the truth. "${name} ${surname}.”

    “${name}? I like it”, he says, leaning against the sofa.
    *goto_scene chapt1michexplain