On Spell Parsing
Parsing the spells on a wand was my first experience with writing any sort of serious parser.
I had written rudimentary JSON parsers and other custom stuff, but those were really straightforward since they don’t perform any computation of any kind. The Moloch spell system has modifiers, which are functions with inputs and outputs (where the inputs are spells, and the outputs are more spells).
There’s also function composition at play - the output of a spell can be an input for another modifier. What do we do?
My solution was to make a stack-based system. I was lowkey into stack based computing at the time, and delved into UXN a little, so that’s probably why. But really, stack programming also seemed like the simplest to implement.
Each spell adds itself to the execution stack from last to first. The execution stack is then cast starting from the earliest addition.
Modifiers take spells out of the execution stack, and put a new one in it.
This means many things. For one, it means that it’s easy to know where the inputs of a spell are in the inventory, they’re just whatever came before the modifier. It also means it’s easy to know when the modifiers aren’t supplied enough inputs, and so I can stop the entire computation as soon as this happens. I could even make some “compile time error” sound play or something! I should do that.
An important thing, too, is that every modifier outputs a spell, meaning that they can work as inputs to other modifiers!
Cool, right?
Files
Get Moloch
Moloch
A wandcrafting roguelike where health is not health points
Status | In development |
Author | Katie And |
Genre | Platformer |
Tags | 2D, Pixel Art, Procedural Generation, Roguelike, Roguelite |
Languages | English |
Accessibility | Configurable controls |
More posts
- 0.16.0 is here!Oct 02, 2023
- 0.16.0dev 8 - New enemy,Oct 01, 2023
- 0.16.0dev7 - It makes a sound!Sep 29, 2023
- 0.16.0dev6 - Spell mods galoreSep 28, 2023
- 0.15.0 - The only thing that kills you is dyingJan 10, 2023
- How To Open Moloch's Command ConsoleJan 03, 2023
- 0.14.2 - More Menu ChangesJan 02, 2023
- Designing A Health System Without PointsJan 02, 2023
Leave a comment
Log in with itch.io to leave a comment.