How to Raise Exception in ChoiceScript

Hi folks, I was wondering if there is a way in ChoiceScript to raise an exception so that an error is produced when a certain line is reached? Had a look on the wiki and the help files but it seems if this exists my google-fu is lacking.

I currently have this, where if a variable is not set it puts a message in the text itself, but I would like it to produce an issue and fail automated tests if the variable is not set.

    #I ask for a coke.
        *if alcohol
            Even though you usually drink, you don't feel like it this evening. 
            *goto pepsi
        *elseif not alcohol        
            As you don't drink, you order a coke. 
            *goto pepsi
        *else
         Error! Alcohol var not set! 
            *goto pepsi

Thanks for the help! :slight_smile:

The most similar function I know is *bug

5 Likes

Yep, I think *bug is what you’re looking for.

1 Like

Notice you can raise errors but you can’t catch them. :joy:

1 Like

Looking a little more closely at your example – you’d want if not(alcohol) rather than if not alcohol. ChoiceScript will interpret the latter as having something to do with a variable called not (which you probably haven’t created – and shouldn’t! Best not to confuse editors, playtesters, and yourself with code like if not or if not(not)…)

And in cases like this where you’re using a Boolean (i.e. true/false) variable, you don’t need the safety net – you could just use *if alcohol and *else, no *elseifs needed, since the variable only has two possible states. When you *create the variable alcohol, you’re creating it to be either true or false; there’s no third “not yet set” option that hangs around until you first use the variable in the game.

If you’re using a numeric or string variable, then *else and *bug can be useful to catch game states that shouldn’t be possible yet. But for that you’d need something like if alcohol > 0 or if alcohol = "wine", not just if alcohol.

1 Like

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