Basics of Luduvo Scripting

Scripting is coming next update, so I thought it would be funny to make a beginner Luduvo scripting guide before the scripting system itself releases.

Ok so actually, scripting is already out. I started this in late June, got busy, came back early July, saw scripting was already partially out, and was like “man there’s no point in making this since scripting will be here in full force soon” and then dropped it until now. At this point, I’m just making this because I’m a Luduvo grifter with nothing better and/or useful to do with my time.

And another update: Apparently, the actual scripting docs will come in like 2 days. So uh… this really is probably completely useless. I really shouldn’t have procrastinated for as long as I did. After July 22nd, check out the actual scripting docs at the aptly named docs.luduvo.com (right now it goes nowhere)

Never mind, Isaac announced that the entire site is being rewritten from the ground up (my condolences, Matt), and then Isaac proceeded to delete the post saying that the docs were coming on Wednesday (lol). In my mind, that also probably means that you also won’t be seeing any official docs site until around September because the site rewrite takes priority. We’ll get them when we get them I guess.

The docs are actually coming September 12th… bro… Anyway, its been so long that I’ve written an entirely different set of docs at Unofficial Luduvo Scripting Docs - Luduvo Scripting Docs. They won’t be as beginner firendly as what I have written here, but they should hold you over until I update that with the unfinished stuff I hidden away for now.

Luduvo on!

Unfinished AND outdated Guide (will be porting to docs soon™

Finally, note that while this is all based on released information, I could be completely off the mark and wasting your time. If you see mistakes, feel free to correct them in the comments or something and I’ll update this. Also note that not all aspects of Luduvo’s scripting API are known to the public, so don’t expect this to be an exhaustive guide unless someone in the engine team can fill in my gaps.

Dedicated to that one guy in the dead Luduvo developer d*scord


The Absolute Basics

In order to script for Luduvo, one must first understand what Luduvo is. Unlike engines from other competitors in the space, Luduvo organizes its engine’s structure around a tactic called an Entity Component System, or “ECS” for short. The nitty-gritty of what this means likely won’t matter much for this guide[1], but know that it will affect how you should approach writing code in ways that I will cover later.

The next essential information to know about is that Luduvo’s scripting language of choice is currently Luau. The exact build of Luau used is currently unknown, but Luduvo will likely be using the latest version of Luau by the time you use it. Since there are already many tutorials[2] on how Luau works, I won’t go over the specifics here.

Finally, understand that while Luduvo Studio has an internal script editor, Luduvo also supports external script editors by storing game scripts in [your Luduvo game directory]/scripts. I recommend using an external script editor[3], as it will likely be significantly nicer to use until the foreseeable future.

The Main Loop

In Luduvo and many other ECS-based game engines, scripts do not automatically run from top to bottom. Instead, scripts are callback-based and have all their logic in 2 special “update” functions that the engine finds and runs every frame.

The first “special” function is called Update. You will be using this function 99% of the time. In practice, it looks something like this:

function Update(dt)
  -- Code goes here
end

Note that the capitalization of the “U” is intentional. If you already know what an update loop is and how it works, skip this section because I’m not going to say anything else of note. If not, I’ll quickly elaborate on the less intuitive parts of it:

The observant will realize the Update takes a dt parameter. dt is short for “Delta Time”, and it’s the amount of time in milliseconds that has passed between now and the last time your Update function was run (which works out to be the amount of time it’s been between frames). Most of the time, you will not need to use this. However, the delta time between frames is basically required if you have something that needs to be updated consistently. For example, let’s say I had wanted to have a 30-second countdown timer in my game:

const STARTING_MILLISECONDS = 30000 -- note that syntax highlighting looks off here because this is being linted as Lua due to there not being support for luau syntax highlighting yet. "const" is a real luau keyword
local timeLeft = STARTING_MILLISECONDS
-- There's no need for these values to be reallocated every frame, so they aren't 
-- a part of the update loop on initial declaration

function Update(dt)
  timeLeft -= 1

  if currentTime <= 0 then
    print("Countdown finished!")
    startGame()
  end
end

This code would only work if the time between Update runs was 1 millisecond every frame. In reality, FPS varies not only between devices (due to differences in hardware) but is also generally prone to fluctuations depending on what’s going on in my game. So if you broke into NASA to play Luduvo on their quantum supercomputers to average 1,000,000 FPS (which means that this Update function would run 1,000,000 times a second), there is no way that this timer would take 30 seconds to complete. Conversely, if you were playing Luduvo on your Samsung smart fridge or a troll lag spikes the game so that everyone is watching a 1 FPS slideshow instead of playing a video game, it would take longer for the game to start than the amount of time it would take a grandma with Alzheimer’s and wooden knees to swim across the Atlantic.

So instead of decreasing the time by a fixed amount, I’d decrease it by dt like so:

const STARTING_MILLISECONDS = 30000 
local timeLeft = STARTING_MILLISECONDS
-- There's no need for these values to be reallocated every frame, so they aren't
-- a part of the update loop on initial declaration

function Update(dt)
  timeLeft -= dt

  if currentTime <= 0 then
    print("Countdown finished!")
    startGame()
  end
end

That ensures that no matter who plays your game or what happens during it, it will always take roughly 30 seconds for the timer to end. dt is also important for things like movement speed, animations/tweening, and anything else that would break if it were told to update too late or too soon.

Outside of Update, the second loop you might see is the PhysicsUpdate loop. As the name suggests, it’s meant to house physics and other math calculations that must be methodically recalculated on a predictable basis. Though 80% of the time, you will never actually use the thing unless you are making a very specific type of game. In the off chance you do, the syntax should look pretty similar to the Update function:

function PhysicsUpdate(dt)
  -- Code goes here
end

Again, the capitalization is intentional. The knowledgeable devs out there might be confused as to why there is still a dt parameter passed inside PhysicsUpdate. After all, the entire appeal of PhysicsUpdate loops is that they always run at a fixed rate (i.e., 60 times a second) no matter what the FPS is. As such, the delta time returned by PhysicsUpdate will always be the same no matter if the game is run on a potato or a NASA supercomputer. I’m just a guy on the internet, so I don’t know the exact reason, but if I were to guess it would be for future-proofing or transparency reasons. Fixed frame rate might change depending on what platform Luduvo is run on (i.e., phones might have lower physics update intervals due to lower processing power), and in general it’s more convenient to get the fixed frame rate directly from the Engine instead of needing to Google it or look at the engine docs. Or I could just be looking too much into this and it was an unintentional typo. Either way, it shouldn’t change how you use PhysicsUpdate loops since you can just ignore it altogether.

And a quick note to the very few people who think that everything will be easier if you use PhysicsUpdate for things that don’t depend on physics, remember that while PhysicsUpdate is detached from the frame rate, the player’s eyeballs still are very much not. Information that heavily relies on player input or needs to be rendered smoothly at different framerates should run every frame, not every X milliseconds.

Server and Client Interactions

Something you will be doing all the time in games is writing code to synchronize game state between the client and the server. In some popular game engines, you might expect this process to be done through a dedicated “server”, “client”, and “module” script you specify before writing any code. However, Luduvo works a bit differently. Instead of there being specific file types you must use to write server and client code, every script can be a client or server script on demand. Reality is whatever you want it to be.

How this is done is very simple, and people who have worked in other multiplayer engines like Godot might find this syntax very familiar: IsServer() and IsClient()[4]

IsServer() is very simple in practice. When you call it, it will return true if the script is currently running on the server, or false if it is running on the client. So, theoretically, server/client logic would look like this:

if IsServer() then
-- Server code here
else
-- Client code here
end

This allows you to keep related code in the same place instead of spreading it across different files. This approach is also pretty convenient when you have code used on both the server and the client. Just remember that variable updates made in a Client-only code block won’t magically sync or be updated when the script runs on the server.

Entity/Objects

Entity Access

Currently, there are 3 ways you can access a runtime Entity (which is generally just a thing that is in your Luduvo project’s object browser) without directly polling for the entity through whatever ECS system Luduvo will have.

This first way is pretty simple: You parent a script to an object or object group, and then you can access the parent entity through script.parent in code. However, don’t mistake this for scripts being a part of the game’s instance hierarchy chain, as you might see in engines like Roblox.

The second way is through something called “script handles.” Script handles allow you to reference an entity through an identity/alias that you physically assign to it. It’s a lot like assigning tagsch


  1. If you are interested, there is a video about this ↩︎

  2. If you are interested in learning about how Luau works, I recommend looking through its official documentation. For people who appreciate video guides, there are plenty that exist, like this one. Note that while the content of video guides will likely always be applicable due to Luau backward compatibility guarantees, they still tend to become outdated easily as Luau introduces better way to do things in future updates. So, you should always try to look for recent tutorials from reputable brands. ↩︎

  3. Personally, I use Zed. But if you’re new, I’d recommend something like VS Code (assuming your computer can handle its bloat) since it’s a pretty popular editor ↩︎

  4. Note that the final name for this might not actually be IsServer() or IsClient (as that might just be Igor pseudocode), but I’m assuming the functionality won’t be all that different from how its described below ↩︎

1 Like

It exists now https://docs.luduvo.com/

YOOOOOOOOOOOOOO