Conditional mishap

I’m having trouble with…

The error I’m getting is:Invalid expression at char 59, expected no more tokens, found: NAMED_OPERATOR [and]

My code looks like this:

*choice
    #"Tonight was a triumph. The audience felt every emotion I poured into the music."
        *if (skill_level > adaptability) and (skill_level > nerves) and (adaptability > nerves)
            *goto high_skilladaptability
        *elseif (skill_level > adaptability) and (skill_level > nerves) and (adaptability < nerves)
            *goto high_skillnerves
    #"Despite the challenges, I'm proud of how I adapted and turned them into unique moments."
        *if (adaptability > skill_level) and (adaptability > nerves) and (skill_level > nerves)
            *goto high_adaptableskill
        *elseif *if (adaptability > skill_level) and (adaptability > nerves) and (skill_level < nerves)
            *goto high_adaptablenerves
    #"There's a certain magic in connecting with the audience. It makes all the pent up nerves worthwhile."
        *if (nerves > skill_level) and (nerves > adaptability) and (skill_level > adaptability)
            *goto high_nerveskill
        *elseif (nerves > skill_level) and (nerves > adaptability) and (skill_level < adaptability)
            *goto high_nerveadaptability

Choicescript doesn’t know how to make boolean operations with more than 2 operands (you have to put parenthesis around conditions so they are evaluated in pairs of two at a time)

*if (skill_level > adaptability) and (skill_level > nerves) and (adaptability > nerves)

should become

*if (((skill_level > adaptability) and (skill_level > nerves)) and (adaptability > nerves)))

In other words, skill_level < adaptability is evaluated first, then the result is compared with (skill_level > nerves). After that the (first result and second result) is evaluated, then adaptability > nerves. Finally, the last two results are evaluated.

1 Like

I got another error after fixing it: It is illegal to fall out of a *choice statement; you must *goto or *finish before the end of the indented block.

*choice
    #"Tonight was a triumph. The audience felt every emotion I poured into the music."
        *if (((skill_level > adaptability) and (skill_level > nerves)) and (adaptability > nerves))
            *goto high_skilladaptability
        *elseif (((skill_level > adaptability) and (skill_level > nerves)) and (adaptability < nerves))
            *goto high_skillnerves
    #"Despite the challenges, I'm proud of how I adapted and turned them into unique moments."
        *if (((adaptability > skill_level) and (adaptability > nerves)) and (skill_level > nerves))
            *goto high_adaptableskill
        *elseif (((adaptability > skill_level) and (adaptability > nerves)) and (skill_level < nerves))
            *goto high_adaptablenerves
    #"There's a certain magic in connecting with the audience. It makes all the pent up nerves worthwhile."
        *if (((nerves > skill_level) and (nerves > adaptability)) and (skill_level > adaptability))
            *goto high_nerveskill
        *elseif (((nerves > skill_level) and (nerves > adaptability)) and (skill_level < adaptability))
            *goto high_nerveadaptability

That’s because all conditional statements inside a choice must be exhaustive. You can fix this in two ways.

  1. Make all conditions exhaustive.

For example:

*if (((skill_level > adaptability) and (skill_level > nerves)) and (adaptability > nerves))
            *goto high_skilladaptability
        *elseif (((skill_level > adaptability) and (skill_level > nerves)) and (adaptability < nerves))
            *goto high_skillnerves

becomes

*if (((skill_level > adaptability) and (skill_level > nerves)) and (adaptability > nerves))
            *goto high_skilladaptability
        *elseif (((skill_level > adaptability) and (skill_level > nerves)) and (adaptability < nerves))
            *goto high_skillnerves
       *else
            *goto somewhere_you_belong

  1. Convert the choice into a fake_choice and allow implicit control so your choices aren’t exhaustive (if you use this route, you have to be very careful so that your choices don’t lead to dead ends)

For this replace choice with fake_choice and in your startup file put

*create implicit_control_flow true

1 Like

So it worked
I simply changed choice to a fake choice

1 Like

This might be a bad solution? Worth double-checking, anyway.

QT was choking on your code for good reason: you’ve not given it anywhere clear to go if e.g. skill_level is less than adaptability in the first two choices. By changing the *choice to a *fake_choice, you’re now ensuring that if it doesn’t meet the very specific conditions in your *if/elseifs, the story will just roll straight on into whatever the next bit of text is after the choice block.

Maybe that’s what you intended–that only a high skill_level player will get a special text snippet after the first choice, varying depending on whether adaptability or nerves is the next highest variable? And that anyone for whom skill_level isn’t the highest variable will just roll on into the follow-up text?

If so, you might still want to make that intention clearer (maybe to yourself, and definitely to anyone reading your code) by throwing in an *else and *goto whatever_the_next_label_is at the end of each option block. In general, I’d suggest ending your *if/*elseif blocks in an *else is a good habit to adopt. Especially for relatively new coders still prone to making basic mistakes, having that habit makes it easier for you (and your playtesters/editors!) to be sure that you’ve thought through all the conditions and aren’t accidentally falling out of the choice into an unintended bit of code.

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the moderators.