how i made a wiring system for Collective Creations

recently, an event callled Collective Creations was hosted on the Collective Unconscious server. the aim of the event was to fill out shallow or long unclaimed open connections, but it ended up being an event where various developers collaborated on some pretty ambitious and impressive worlds instead (and hey, those worlds did end up filling the free slots!).

at the start of the event, Noahrav (who made the game’s record player / sound room feature) reached out to me with a simple question: would i be interested in making a fully featured wiring system with logic gates, inspired by the game Turing Complete?

sounds ridiculous,

i’m in.

An image of the main area of Spirit Processing Unit, showing a waterfall, floating pillars with egg-shaped statues and a large white walkway of stairs.
the main area of the Spirit Processing Unit

i ended up making the code and layout for the world as well as drawing some decorations; Noahrav made the music, the background and the main assets for the wires. most of the work for the system was actually done in the last week or so, as we ended up getting distracted by making an automatic changelog generator (or rather upgrading the unpublished one i made a while back to include stuff stored in the .ldb file).

we started with a fairly large list of elements to add, and surprisingly many have made it into the final product: wires, switches, screens, AND gates, OR gates, XOR gates and NOT gates. we initially wanted to make multiple colours of wire that wouldn’t interact with each other as well as advanced timers, but there were some technical limitations that held them back.

A black room with two white creatures, a lone wire, and a single wire connected to a screen and a switch.
the first time i got the system working!

events in RPG Maker 2003 cannot have their own switches or variables. the only data that they can carry over a frame is their current rotation, which only allows for a total of 4 states. for the wires these states are “about to power side 1-4”. while this does mean that a “fully powered” wire will always try to power one of its sides, since that same side cannot touch itself, this effectively prevents the system from locking up. however, move events cannot be processed in the middle of a frame, so it’s necessary to wait a frame between each external call, slowing down the system. this meant that we couldn’t implement precise timings.

An image of two wires. The first one is labeled ''time to turn this wire on'', and the other one is ''oh boy! i found another wire! time to start (or restart, if it's going) its call. then i can be turned on :)''
a very helpful diagram that i sent to Noahrav to explain event call issues

additionally, only one chain of event calls can be active at a time, and every time an event is called while it’s already executing code, it’ll forget its position and start again - hence why we need to store which powering step the wire is on instead of whether it is powered or not. the consequence of this is that turning off the wires is a pulse just like turning them on instead of a lack of signal, so powering the same wire line through multiple means causes issues when you turn them off. also, if the wiring system ever looks like it locked up for a moment despite being done, it’s because it’s actually processing all of the queued events in the callstack.

technically, since all of the wire events are marked as “activated with action button press”, the player wouldn’t be able to move while the wiring system is running. however, there was a workaround for that: calling the events through a parallel process that read the player’s key inputs was enough to let the player move again.

An image of various files, including text files and a Python script; one file is selected, and it has a size of 120.9MB.
a helper program for event generation, and an extracted map file that's a bit large

the most interesting part was duplicating all of the wiring system’s events. since you can’t instance an event in RPG Maker 2003, all of the wire events need to exist ahead of time. this means that the maximum amount of elements is limited - i capped each element at 500, though 1000 wires exist on the map. scaling these numbers up would cause two major issues: large amounts of lag (my laptop is pretty beefy, and with the 5000 events in the map total it can’t run the map smoothly at 10x speed!) and game crashes related to reaching the event call stack limit of 1000 (which is especially worrying considering there’s no way to just save anywhere, and that this area is fairly deep). copying the events alone required an external script that i ended up asking Noahrav to write for me. thanks to the wonderful folks over at EasyRPG and their lcf2xml tool, we were able to turn the map file into an xml file to then parse with Beautiful Soup. the xml file came out to around 122mb, which when zipped caused the file to act as the world’s most basic zipbomb, which was pretty funny. recompiled, the map file itself is 7.1MB.

the visuals and music were inspired by the game Smash Hit, with a clean, simplistic artstyle, though we also spiced it up a little with some waterfalls, pillars and railings inspired by old staircases - hence the status of the main area as a classic staircase world, a fangame staple. the wiring system area was originally smaller, but Noahrav convinced me to expand it. we also wanted to add a little gate or two in the main area, but the RPG Maker 2003 in-editor event limit is 5000, so we’d need to sacrifice some of the other pieces for it, and for some reason i couldn’t get the wires to work outside of the wiring area anyways.

and so, after about a week of tinkering, we had a surprisingly decent wiring system going, despite all the adversities and limitations! we hope that you’ll enjoy messing around with it when Collective Unconscious comes out on YNOProject.


Categories: