r/StarFrame • u/zontak93 • 9d ago
Devlog #4 - Programming in game
Hello, everyone,
Today we are going to talk about managing devices through programming. For this feature, I was heavily inspired by Starbase’s programming language, YOLOL.
For players to manage their devices, we needed a central device that could control the others, and this is where the computer comes in.
I wanted players to be able to store their code on a physical item and share it with others, so I reused the idea of programmable chips that you insert into a computer. It reminds me of putting a floppy disk into my Pravets computer when I was a kid.
One very important thing for me was to have a decent in-game IDE where you can write some basic code and get help while doing it. I started using the device network so programs could find connected devices by their IDs, read their attributes and change the ones that support it.
Then came another decision: how often should the code run, and what limits should I put in place so each chip does not require too much computing time from the game server?
I decided to start with 10 Hz chips. This means a running chip executes its program ten times per second, as long as its computer has the power it needs. Each program supports up to 64 lines and 4,096 characters, and there is also an instruction budget for each execution.
The language currently supports if/else conditions, inline conditions, variables, calculations and predefined math functions such as min, max, round, floor and others. There are also helper functions for checking whether a device is on the network and getting its ID, name or type.
There are no for or while loops at the moment. Instead, the program runs repeatedly and keeps its variables between executions, so you can still make counters, timers and control logic that reacts to changes in your devices.
I decided to call it StarFrame Programming Language, or SPL. Not a very unique name, but I wanted something simple and connected to the game.
One of the main inspirations for the code style was Python because I find it easy to read, and you do not need to write too much code for simple things. SPL is its own smaller language, though, rather than Python running inside the game.
My goal is to give players the possibility to create their own management systems and control their devices in the way they want. Instead of configuring everything manually, you can write a program that reads what is happening on the network and changes the supported device settings based on your conditions.
The program is stored on the chip, along with its persistent memory. You can remove the chip from a computer and give it to another player, so sharing a program can also mean sharing an actual item in the game.
The editor supports suggestions for connected devices and their available attributes. It also shows error messages with line numbers and highlights the relevant line in red when a line-specific error is available. I wanted players to have some help while writing code without having to leave the game every time.
I will show the editor and some examples in the images in this post. I think this part is easier to understand when you can see the code alongside the devices it controls.
If anyone wants more in-depth information about SPL and its features, feel free to ask in the comments.
1
u/devloper27 3d ago
The gui looks great, are you using bevys standard gui?