It’s possible to write an “infinite loop” bug in ChoiceScript, where the game keeps running the same lines of code over and over again, forever. These bugs can be hard to find and fix.
Last year, we announced that our Randomtest tool would begin enforcing limits on infinite loops.
Now, in the latest version of ChoiceScript on GitHub, we limit infinite loops in actual games as well.
If your game has an infinite-loop bug, your players may now begin seeing errors like this:
startup line 31: visited this line too many times (1000)
This error occurs when a line has been run (“visited”) 1,000 times in a single playthrough, which is a strong indication that your game has an infinite loop. Without this, ChoiceScript would just hang forever if you hit an infinite loop.
I thought it might be possible that somehow you’d actually want to run a line 1,000 times in a single playthrough, so there’s a command to support that,
*looplimit , which you can use like this:
*looplimit lets you raise or lower the limit to any number you like.
You can can also turn off the looplimit with
*looplimit 0 , but I don’t recommend it. Running a line a billion times should be good enough for anybody. (The maximum possible looplimit is approximately one trillion (12 zeroes), but, seriously?!)
Last year, we initially restricted infinite loops only in Randomtest, to ensure that we wouldn’t force games to crash incorrectly. But we’ve found that a number of games have been using
*if (choice_randomtest) to make Randomtest behave substantially differently than they do in real life, preventing Randomtest from catching infinite loops. We think it’s better to fail with a clear error message than it is to just hang forever.
The best way to prevent these errors is still to run Randomtest on your game, but if you’ve been using
*if (choice_randomtest) to change Randomtest’s behavior, at least now you’ll get a clear error message, rather than a frozen game with a mysterious blank screen!