Hint #7 -- Changing the World
Remember I talked briefly about "live" objects (or entities...) in the Store instead of "dead" ones that get drawn implicitly? One of the benefits of the former is that you can easily change them dynamically. This has important benefits for development beyond just unifying way you store things.
When the objects are live, you can directly access them in the Store, modify their properties and see instant updates. To get started, pop open the web console in your browser while your game is running. The Entity Store (JavaScript variable STORE) is a global variable you can access:
You can use all the web debugging tools at your command (and there are many powerful ones!) to access and interrogate what's happening in your game. You can also use the Canned Heat query functions:
Remember that Urlang compiles directly to JavaScript, right? And because you're able to access the entities, you can change their properties, right in your console window. That's how I fine tuned a lot of my text placement for the title and credit screens in Kipple Kat. I would put in rough coordinates for things, then I would adjust them on the fly to get them where they really needed to be:
As I change it in the console, the text moves up and down (or down and up, in this case). Once I have it where I want it, I note the latest number and update the source. Not completely smooth, but way better than trying to update a number, recompile, renavigate to wherever it is in the game, deciding it's wrong, then updating a number... The point is, live objects are your friend!
Because the E-S encourages a generic approach, I can do the same thing with almost any displayed object -- they all work the same way because they're displayed or operated on by the same mechanisms.
Have you ever wanted a level editor, or some way to dynamically modify your game world? With Canned Heat, you get it almost for free. To add the layout editor (because Kipple Kat doesn't really have traditional levels...) was about 150 or so lines of code. Most of that was new key handlers to drive a cursor -- you guessed it! -- Entity around and select what it rolled over. I didn't have much time to be fancy, but I was still able to: move a cursor, add new entities at the cursor, move them around with the cursor, delete selected objects, delete all objects (clean slate!) and dump the current state of the layout to the web console. Rather rough, but effective -- In about twenty minutes, I was able to do most of the layouts seen in the game. And that time includes fixing a bug a found along the way!
When I first made Canned Heat available, I provided four simple example games that I used to validate the process. My jam entry (demonstrating the editor among other more advanced techniques) is now one of those examples. And, while I'm very happy with it and how it worked out, it's only scratching the surface.
So, if you're writing games in Lisp for the web, I hope you'll have a chance to check out Canned Heat. Thanks for reading!