Conditional scenes HELP

Help. I’ve been trying to figure this out for three hours.

It’s only my third day coding my first hosted game. I want to write a piece of text that is conditional to a previous choice the player made. That choice is long gone and I don’t want to code it inside another choice. So far it looks like this:

You jerk awake, rapidly surficing from deep sleep to the sound of knocking.

You get up and stumble to open the door. It’s your landlady, fresh and as intense as the night before.

"Good morning!" she says. You mumble something and step aside to let her through, wiping your face. You realize you were so tired you didn’t even put on the pyjama and fell asleep in your normal clothes, which now look like a cow chewed on you.

if (var = true)
** goto renate

elseif (var = false)
** goto hildebrand

*label renate

"Good morning, Renate," you say as you close the door. Renate puts the newspaper she promised the night before on the table next to the pack of cigarettes.

"Riveting reading," she says and you are pretty sure she’s being sarcastic, but it’s hard to detect sarcasm in German. You should really learn the language better.

*page_break

*label hildebrand

"Good morning, miss Hildebrand," you say as you close the door. She puts the newspaper she promised the night before on the table next to the pack of cigarettes.

"Riveting reading," she says and you are pretty sure she’s being sarcastic, but it’s hard to detect sarcasm in German. You should really learn the language better.

*page_break

I’ve changed this so many times in every possible way I could think of. What am I doing wrong? If I don’t get an error, it just displays both of the choices one after the other.

Thanks for helping.

For starters, it’s the best to use triple grave accent ``` to preformat your text (</> button at the comment-editor’s toolbar). This way, we can see the indentation and check if there’s something wrong on that.


As for the “choice,” the term is “choice-body”; content of an #option.

The problem happened because you stacked each choice-body on top of each other. The code would evaluate/process/resolve the first body, and then would proceed to the next one since you just used a *page_break.

To solve this, put another *label as jumping-flag and *goto accordingly at the end of each bodies.

1 Like

if (var = true)
** goto renate

elseif (var = false)
** goto hildebrand

Highly recommended: use *if/*else for tests like these.

*if var
    blah
*else
   blah

Also, you don’t have to say *if (var = true)–you can just say *if var.

1 Like

Also, if it is just a small thing and you don’t want to make a new scene, you can write it like this, as long as the variables renate and hildebrand has been set earlier, the text should just show the variable you have used. Useful for small text snippets that doesn’t warrant an entire scene.


You jerk awake, rapidly surficing from deep sleep to the sound of knocking.

You get up and stumble to open the door. It’s your landlady, fresh and as intense as the night before.

"Good morning!" she says. You mumble something and step aside to let her through, wiping your face. You realize you were so tired you didn’t even put on the pyjama and fell asleep in your normal clothes, which now look like a cow chewed on you.

*if renate
      "Good morning, Renate," you say as you close the door. Renate puts the newspaper she promised the night before on the table next to the pack of cigarettes.

      "Riveting reading," she says and you are pretty sure she’s being sarcastic, but it’s hard to detect sarcasm in German. You should really learn the language better.

*if hildebrand
      "Good morning, miss Hildebrand," you say as you close the door. She puts the newspaper she promised the night before on the table next to the pack of cigarettes.

      "Riveting reading," she says and you are pretty sure she’s being sarcastic, but it’s hard to detect sarcasm in German. You should really learn the language better.

The text then continues as normal, for both variables.

Thanks for replying everyone - I keep trying and they all either end in an error or display both choices. So to give you all the info (because maybe I made a mistake in startup or the choices this links to)

*choice
	#Confront her about her rudeness
		You have had just about enough of her hostility.
		[n/]
		[n/]
		"I know it's late but you really needn't to be this rude," you say. Then you shrink in size and spirit as she pins you down with an even more intense stare.
		[n/]
		[n/]
		"And there is no need to throw a hissy fit just because I didn't roll out the red carpet, your majesty," she says, quietly enough that no one can eavesdrop. Then she turns around and walks off without another word.
		*page_break
		*goto unpacking
		*set (var = false)
	#Thank her
		You gave her your best grateful smile witha little nod.
		[n/]
		[n/]
		"Thank you, Miss Hildebrand."
		[n/]
		[n/]
		She gives you a once-over and something about her expression changes, like she's evaluating you anew.
		[n/]
		[n/]
		"Call me Renate," she says.
		[n/]
		[n/]
		You smile and extend your hand again. This time, she takes it.
		"Konrad," you say. You shake hands and she turns to leave.
		[n/]
		[n/]
		"Good night, Konrad."
		*set charm +5
		*set friendship +15
		*page_break
		*goto unpacking
		*set var "renate"
	#Ignore her
		You are this close to telling her off, but decide to let it go. Maybe she's just tired, and maybe she will be this hostile always, but you're not the kind of man who jumps into people's faces at the first sign of offense. More like the fiftieth, but you blame that on your British upbringing.
		[n/]
		[n/]
		You give her a small nod of acknowledgment and walk into the flat,closing the door behind you.
		*page_break
		*goto unpacking

(I tried to include it with every choice in every way, all together or just one, this is the latest version)

This is what the scene looks like now and it keeps saying the variable is neither true or false

"Good morning!" she says. You mumble something and step aside to let her through, wiping your face. You realize you were so tired you didn't even put on the pyjama and fell asleep in your normal clothes, which now look like a cow chewed on you.

*if var
	*go to renate
*else
	goto hildebrand

*label renate

"Good morning, Renate," you say as you close the door. Renate puts the newspaper she promised the night before on the table next to the pack of cigarettes.

"Riveting reading," she says and you are pertty sure she's being sarcastic, but it's hard to detect sarcasm in German. You should really learn the language better.

*page_break

		
*label hildebrand

"Good morning, miss Hildebrand," you say as you close the door. She puts the newspaper she promised the night before on the table next to the pack of cigarettes.

"Riveting reading," she says and you are pertty sure she's being sarcastic, but it's hard to detect sarcasm in German. You should really learn the language better.

*page_break

and in startup, I created it like this:

*create var "renate"

I see. I see some problem, but the main one:

  1. Put the *set var commands above the *goto. Otherwise, it won’t get resolved.

For minor suggestions:

  1. Why did you use [“renate”] and [false] as the content of the var? Both are different datatype (string & boolean respectively); not recommended to use different datatype for a function.
  2. No need to do double [n/]. Simply double carriage return instead (Windows: Enter, Mac: Return). Avoid potential bug with screenreader apps.
3 Likes

Szaal is right, you seem to mix up the variable types. If you use “renate” this is a string, if you want to check for a String you need
*if (var = “renate”)
if you want a boolean, which I prefer since it is easier to spot a mistake, you would create the variable
*create renate false
and then you can set it to true, when you have met renate and then the if is:
*if renate

Oh no, I was too quick to celebrate. Now it jumps to the Hildebrand option no matter what. I tried to just change

*if (var = true)

to

*if var

But then that error comes up again saying it’s neither true nor false.

Oh my god Szaal you did it
THANK YOU
I spent half a day on this!
I used two different datatypes because I still don’t understand them :smiley: I’m learning, but as I said, this is my third day writing code (even such simple one as this). And what I’ve seen from forums, I’m sure I’ll struggle a lot more as I get deeper into the story.

2 Likes

Np. Boolean is a simple light-switch on/off, so it’s best used for specific, scene by scene cases, or content-lock-based conditional checks. String, on the other hand, is best to keep it away from conditional checks as far as possible.

But since CS is the closest in terms of “coding that can be read by non-coder,” I don’t really mind using them in conditional checks. It’s also quite refreshing to break the habit of *if var = 1, 2, 3, etc.

1 Like

In general, what made me understand Choicescript was realizing that it all makes sense if read out loud. I overcomplicated everything at first because I thought codes needed to sound codey, but it’s really all just words. Booleans made my life so much easier, having flags be true/false made it so easy to check for minor things.

5 Likes

I also did
*create renate true
and then I set the choices in choice-body each to either true or false
and I did

*if renate
	*goto nice_renate
*else
	*goto hildebrand

And now it’s back to desplaying them both

I can’t set it to (var = “renate”) because the error about invalid name keeps popping up, I don’t think it reacts well to the quotation marks
I tried to do a boolean but if I
*create renate false
how do I set it? Because when I did
*set renate
It popped up with an invalid set instruction error

It may be that var is a word that is reserved for the code itself? But I do not know that for sure

I haven’t done this much combinatorics since fifth grade.

I did another experiment, created the variable as a string in startup, then set it in the one choice in the middle, and now I’m struggling with figuring out how to command it

*if var "renate"

says it’s expecting OPERATOR instead of STRING and

*if renate

says it isn’t a valid value

CS tries to take a lot of the programming effort out of creating a CYOA type game but it is still a pretty basic programming language at its core and, as such, you have to tell it exactly what it’s supposed to be matching in IF statements.

Your statement (*if var “renate”) is confusing it because you’re missing the equality symbol between the variable (var) and the string “renate”. That should probablyt be *if var = “renate”.

It’s important to keep track of what types your variables are because you can’t compare one type with another different type. If you create a variable as a boolean (true or false), you can’t compare it to a string or allocate a string to it. I suspect this is what you’re trying to do.

In your second statement (*if renate), you’re asking it to resolve the value (true or false) of a variable called renate but you haven’t declared one with that name.

BTW, it’s not a good idea to use ‘var’ as a variable name :wink:

2 Likes

That did clear the OPERATOR issue, but now, AGAIN, it’s showing both options at once. I think something’s wrong with the *else command.

OK, I have to vacate the computer now and honestly I’ve had enough for today, but I also tried this:

*if var = "renate"
	"Good morning, Renate," you say as you close the door. Renate puts the newspaper she promised the night before on the table next to the pack of cigarettes.
	[n/]
	[n/]
	"Riveting reading," she says and you are rertty sure she's being sarcastic, but it's hard to detect sarcasm in German. You should really learn the language better.
	*finish

*elseif
	"Good morning, miss Hildebrand," you say as you close the door. She puts the newspaper she promised the night before on the table next to the pack of cigarettes.
	[n/]
	[n/]
	"Riveting reading," she says and you are pretty sure she's being sarcastic, but it's hard to detect sarcasm in German. You should really learn the language better.

and now it only shows the nice_renate label again.

You can’t have *if/*elseif.

You can have *if/*elseif/*else, or *if/*else, but never just *if/*elseif.

Also, why use [n/]? You can just hit the enter key to skip a line. [n/] is the same as “*line_break” which you will rarely need unless you are writing verse or a letter or other oddball things.

2 Likes

*elseif needs a test after it. *elseif on its own is the same as *if on its own. It doesn’t give the computer anything to actually test against.

Change the *elseif to just *else.

You’d use *elseif if you wanted to do something like:

*if var = "renate"
    Do something for renate here.
*elseif var = "susan"
    Do something for susan here.
*else
    Do something if neither of the above tests passed.
2 Likes