ChoiceScript updates: Bug fixes that could cause failures in your code

I’ve fixed a couple of ChoiceScript bugs this evening that could cause your game to fail tests (Quicktest and/or Randomtest).

Bug fix: Randomtest is not allowed to run *restore_checkpoint

If Randomtest ran *restore_checkpoint, it would just run itself in circles, never finishing.

Now, if Randomtest randomly stumbles upon a *restore_checkpoint command, it will fail with an error.

Randomtest is not allowed to run *restore_checkpoint. Use "*if (not(choice_randomtest))" to prevent this error.

Block Randomtest from running *restore_checkpoint like this:

*choice
  #Continue to the next chapter.
    *finish
  *if (not(choice_randomtest)) #Restore to the previous checkpoint.
    *restore_checkpoint

Bug fix: *fake_choice sometimes infected later *choice commands

The bug worked like this, for example:

*fake_choice
  #1
    1
    *goto next
  #2
    2
    *goto next
    
*label next    
*choice
  #3
    3
  #4
    4

If you pick #3, this code should fail with an error:

It is illegal to fall out of a *choice statement; you must *goto or *finish before the end of the indented block.

…but it didn’t, because ChoiceScript wrongly thought that we’re still in a *fake_choice from earlier. Now, if you upgrade to the latest version of ChoiceScript, it does fail with that error.

Sometimes, instead of “illegal to fall out,” the error says “Expected choice body” instead, as in the example below, where there’s no body for the #4 choice.

*fake_choice
  #1
    1
    *goto next
  #2
    2
    *goto next
    
*label next    
*choice
  #3
    3
  #4

That's the end!

To fix these new “illegal to fall out” and “expected choice body” errors, convert *choice to *fake_choice, or use implicit control flow

The error messages provide suggestions for how to fix the error: add *goto or *finish before the next #option, or add an actual body for each #option in a *choice.

But the easiest way to fix these bugs is to look at the line of code that failed and scroll up to the nearest *choice. When you change that *choice to a *fake_choice, you’ll fix the error, because *fake_choice is allowed to have empty bodies and to skip having a *goto or *finish before the end of their blocks.

Or, you can use implicit control flow. Implicit control flow turns every *choice into a *fake_choice. Some people swear by ICF, others don’t like it.

Converting to ICF to fix these issues is probably overkill; you can usually fix the issue just by converting a handful of *choices into *fake_choices.

37 Likes