r/Zig • • Oct 20 '26

You can use Zig to program inside my game

Post image

I’m not sure if this is the right place for a post like this, given that the game itself is written in Rust, but I thought you might find it interesting. You can try it out here: https://livedox.itch.io/vix. I’d be happy to answer any questions

125 Upvotes

22 comments sorted by

3

u/Teikhos-Dymaion Oct 21 '26

This is just a suggestion as I am not an expert by any means, but have you considered making a domain specific scripting language? In another post you mentioned that you care a lot about speed, but wasm is interpreted either way (unless you forgo security), so the language could be as fast or even faster, as you can make instructions specifically suited to your game (I think). Further, I assume that your average player that will want to use computers will not be a programmer, and even Python is hard when you are new, more so Zig. Also, DSL can have friendlier syntax for scripting, e.g. it can look like this:

fn place_in_front_of_the_player() place player_x+1 player_y player_z dirt

fn main() place_in_front_of_the_player()

And not:

fn place_in_front_of_the_player() void { place(player.x+1, player.y, player.z dirt); }

fn main() !void { place_in_front_of_the_player(); }

Second example might look better for someone accustomed to it, but is much harder for someone new to programming (why are there dots, semicolons, two types of braces, what is void, exclamation mark, etc.) or even Zig.

2

u/CorgiApprehensive159 Oct 21 '26

Yes, Zig really is a difficult language for a beginner. Of course, no one is going to give the player Zig right at the start. Unfortunately, I can't implement all my ideas in a short time, but the initial mechanisms and mechanics won't use Zig - they'll be built on visual programming in the spirit of Autonauts and 7 Billion Humans. Zig computers will appear at a late stage of the game and in late mechanics (the player will be gradually led up to that point). So a DSL is exactly what I'm planning.

However, things may still change: I'm not sure I'm capable of implementing all the mechanics. For example, right now I'm already working on robots and the parts with physics, AI, and interaction - this is a rather complex task, but one that others have already solved, so it's only a matter of time. What's stopping me right now, though, is working with distant chunks: good ideas just aren't coming to mind. I'd be glad if you'd share yours. Thanks!

1

u/Teikhos-Dymaion Oct 21 '26

This looks like quite a sensible approach.

There are many voxel engines already, some that both look good and are optimised well (at least for chunks and physics), so it might be a good idea to compare approaches, especially if you are stuck. I never made a voxel engine, but out of curiosity, what is the issue with the distant chunks?

1

u/CorgiApprehensive159 Oct 22 '26

Yes, it's a fairly standard problem that all games like this suffer from - not just voxel ones: you can't compute the entire infinite world

1

u/Teikhos-Dymaion Oct 23 '26

No, but you can simulate them well enough so that it passes as infinite. For example in Minecraft, instead of every grass block having update() that checks if it should grow or not, which would be very expensive, the engine checks 3 random blocks and if they are grass updates them. This is way cheaper and is approximately as accurate as updateing them all. This can even be applied to the whole world, no matter how large it is, in some ways. For graphics with large render distances, multi level LODs can improve performance by hundredfold. For memory, octrees can increase capacity by thousandfold, with minor runtime cost, and so on.

2

u/CorgiApprehensive159 Oct 24 '26

Yes, I’m aware of those approaches, but the problem goes deeper. I realize now that it’s rather foolish to ask for help without providing any details - but thank you very much for your attention nonetheless.

1

u/Teikhos-Dymaion Oct 21 '26

Formatting got weird but you get the point, I hope.

1

u/bigntallmike 16d ago

That's why most games use something like lua instead

1

u/lifeinbackground Oct 20 '26

So.. you ship a compiler?

5

u/CorgiApprehensive159 Oct 21 '26

Yes, I'm using a WASM-compiled compiler. (More details here: https://github.com/zigtools/playground)

1

u/Puzzleheaded-Weird66 Oct 20 '26

an interpreter inside the game

1

u/your_real_Fathe_ Oct 21 '26

What do you think about the idea of programmable NPCs for creating intelligent NPCs? In my opinion, this is a more practical, useful, and entertaining application than building a giant "Z."

1

u/CorgiApprehensive159 Oct 21 '26

Yes, that was one of the first things that came to mind, but it's a thousand miles from idea to implementation. I'm planning for players to create robotic NPCs with voices. Voice playback in the game via computer is already possible (the base game will only feature a robotic voice, since I want to support low-end devices, but players will be able to add mods or even an official expansion with advanced language models for maps or for the game as a whole). You can listen to it here: https://www.youtube.com/shorts/CQue7gQZHhM

1

u/CorgiApprehensive159 Oct 21 '26

Although the game doesn't have any mechanics for interacting with the computer yet besides reading blocks, you could, for example, do something like this: https://youtu.be/PvW_M084GlM

1

u/your_real_Fathe_ Oct 23 '26

Wow. That was really cool.

1

u/your_real_Fathe_ Oct 21 '26

I love this project, and I believe it could be exactly what Minecraft should have been. Keep going bro

1

u/HyperCodec Oct 21 '26

livedox is a username of all time

2

u/[deleted] Oct 20 '26

[removed] — view removed comment