Rogue has a conditional called
which that is analogous to C's
switch conditional. It has the added perks of allowing any kind of expression (not just literal integers), allowing multiple expressions to match a single case, and the arguable improvement of not having control flow drop through to the next
case if you forget to put a
Slag (Rogue's ancestor) had a nifty
caseNext command as well. It's pretty simple: writing
caseNext is equivalent to writing
case N+1, where
N is whatever value the previous case checked for.
I had mostly forgotten about it, in large part because I hadn't needed anything like since I started work on Rogue. But while working on Axor the Mighty today, suddenly I needed it real bad!
I'm starting to create the tutorial levels. Each one has a single state integer called
progress which is used to control the next step of the tutorial. The commands issued in each state automatically increment
progress. With this system all that matters is that each case is the next sequential integer; the integer values themselves aren't important.
At first I had
case 1, ...
case 10. After needing to insert a new step a few times - and having to reorder all the case numbers - I decided to bring
caseNext back to Rogue. Now it's much easier and quicker to reorder those commands and insert new ones!
It was pretty simple to implement. I've never really thought to share compiler implementation details in my blogs before, but I'll start now with a link to the commit on GitHub:
Okay that preview text is a little rough but good enough!