I'd been vaguely aware of Lua from my tangential time spent around the games industry. In particular I knew of it as the "advanced mode" if I ever wanted to go there when building custom levels for Marathon Aleph One. That being said I'd never actually used Lua.

As I kept imagining experiences in Cozy Corner my item schema started to expand, my editor grew more complex, and it was clear that a bunch of things I would like to do just weren't possible. I wanted a greeter to welcome you to town, I wanted a fishing hole were there was a chance to get a fish item...

What I wanted was a way for items and NPCs to script behavior and so I embarked on writing a custom behavior layer.


While I've build programming languages before my thinking on cozy corner was that I'd stick with a machine readable JSON AST. I can whip up a good AST in a few minutes. What proceeded was a 10 minute adventure in building an AST and a half day adventure in building an AST editor that was moderately usable.

In the end my adventures in visual coding ended where so many other's have. A realization that I wasn't going to do better than a code editor and Lua.

At first the Lua scripts were clunky, I went through a few different incarnations before realizing the beauty.

on("interact")
while true do
  wait(10)
  if chance(.3) do
    open("at://did:plc....") -- grant a fish item
    break
  end
end

I could write what was effectively a procedural script, allow my existing message passing infrastructure to make sure that things landed on "ticks" and have a blocking script. A behavior scripted in Lua could trigger a "moveTo" or a dialog prompt. The script would read sequentially but the runtime would be non-blocking.

With Lua decided I started to work through the newfound power of my engine.


Up until now the "backend" of Cozy Corner had been very light weight, it was really just a simple relay telling you where different people were in a room and what (if any) text bubble to render over their heads. The Lua script added a bit to that complexity, It also opened up questions like, should an NPC follow the same behavior for all the people in the room, or should the other avatars in the room just be placeholders showing where they are?

I spent the better part of a day building out pseudo random number generators, sequence ticks, designing a lua compiler that could produce a full state machine that could support reordering of events. It was glorious, but so overwrought.

In the end the answer was obvious – for a multiplayer "MMO" style game we were going to need to have game servers. These would be an app layer, authoritative system. Locally we could do some path finding, and sub-frame interpolation but the majority of the interaction would be server driven. This let me lua scripts pair down extensively and get much, much more readable.

It was now time to really build this system. I threw out what I had (again) and this time committed to using the excellent Pixi js engine.

It felt like the project had really turned a corner previously I'd been making progress and hitting walls but now there was a clear path to the end.

Up next, Atmosphere Conf derails me and rpg.actor spurs me on.