Question of the night: Conditional options

I want to use conditional options to essentially make the dialogue options make sense. What I’m doing based on the CoG how-to pages isn’t working well, though. I’m getting an error message about “couldn’t extract another token” on the first line here. And, honestly, I assumed this was something I’d need help with, so I’m not surprised.

Essentially, there are four possible options for *respo, set by a previous choice. One of these options is “hand”. The other three are not. I’m trying to write it so that, based on what the player did during the previous choice, one or the other of these options is available in this choice. Note that there are another few, non-conditional options available in this choice, which I didn’t show to keep this shorter.

As always, very much appreciate the help!

John

*if (respo "hand")# This, honestly,  just requires a bigger hardware intervention. You're going to have to move more than just wires. 
	By the time you're done, you've rearranged a third of the server room. Also by the time you're done, the intruder only has access to your bathroom maintenance log. So mission accomplished. 
	*line_break
	You look up at Gloria, who has been helping you lug wires and CPUs around the room, and smile. 
	*set might %+4
	*set agility %+4
	*set ethical sense %-4
	*goto notice
*else #This really does require a hardware intervention. You grab a laptop and sprint to the server room. 
	You arrive at the server room at a run, a fascinated Gloria trailing behind. Soon, both of your hands are full of wires as you start routing things the old-fashioned way. It only takes a few minutes after that before the intruder is booted from the system entirely.
	*line_break
	Sweaty and out of breath, you give Gloria a smile. 
	*set agility %+4
	*set mental_acuity%+4
	*set ethical_sense %-4
	*goto notice3

I think the “can’t extract another token” error specifically comes from the fact that you don’t have a = in your condition. It would need to be (respo = "hand"), not (respo "hand").

When you’re checking Boolean (true/false) variables, you can if you wish omit operators like = or > (you can just write e.g. *if male rather than *if male = true, and *if not(male) rather than *if male = false), but for string variables like your respo, you need to keep an operator in the conditional check, or ChoiceScript gets confused.

To help you fend off the next error(s) you’d get: very few ChoiceScript commands work in the same line with #options. *else isn’t one of them. *if can be, but breaks easily, so I try to avoid using it inline. (The commands that do work well inline are *hide_reuse, *disable_reuse, and *selectable_if.)

The best way to make conditional options work is by using indents:

*choice
    #First non-conditional option
        *goto notice
    *if (respo = "hand")
        #This honestly just requires...
          *goto notice
    *else
        #This really does require a...
          *goto notice
    #Final non-conditional option
        *goto notice

For that example code to work, the *else option needs to immediately follow the *if option. Separating them, e.g.

*choice
    *if (respo = "hand")
        #This honestly just requires...
          *goto notice
    #Non-conditional option
        *goto notice
    *else
        #This really does require a...
          *goto notice

didn’t crash my game when I tested it, but it did prevent the *else option from ever showing up, even when the condition was false.

If you wanted to split up two conditional options, e.g. because you felt that the choice block read more naturally with something in the middle, either code example above will work if you replace *else with *if (respo != "hand"), where the != means “not equal to.”

As a final FYI, your game will work better on screenreaders (and read better on mobiles) if you use para breaks rather than *line_break. That is, instead of this:

You arrive at the server room at a run...
*line_break
Sweaty and out of breath, you give Gloria a smile. 

just do

You arrive at the server room at a run...

Sweaty and out of breath, you give Gloria a smile. 

*line_break is useful in lists, lyrics, and a few other special cases, but it shouldn’t be your default for paragraph endings, since you can’t easily indent the start of the new para in the ChoiceScript UI. You’ll end up getting complaints about “wall of text” from your readers, who’ll often find it hard to discern when one paragraph ends and the next begins.

4 Likes

You’re totally saving my a** here and I really appreciate it! If you ever need someone to read some medical portion of your story for accuracy/realism, let me know, and I’d be happy to help.

Thanks!!

John

1 Like

Thanks, John – I may well take you up on that!