Skip to main content

ModScript Structure

Let's talk a bit about how ModScripts are created, organized, and executed within the Level Builder.

ModScript Panel

The ModScript panel is where you organize and write all your code:

On the left column, you have the "file" explorer, which shows all the ModScripts attached to the currently selected MemeItem. Each row has the ModScript title, and a number input field to set the execution order of the ModScript within that MemeItem.

At the top, going from left to right, you have a button to add a new script to the MemeItem, a text input field to provide the ModScript's title, and buttons to open the Community Mods panel, the API Reference panel, and the website for this very tutorial thou art reading at present time GMT.

Then all the way on the right, there is a number input to set the execution order of the selected MemeItem. More on that soon.

There is also a dropdown at the top of the explorer to change the sort order the ModScripts show up:

Main Code Editor

Ok so the main code editor is very basic, providing simple syntax highlighting and undo & redo.

If you want better a better coding experience, you should probably use a good code editor that supports Lua, such as VSCode, and then copy and paste your Lua scripts into the in-game code editor.

These are the buttons to delete the open ModScript, and undo & redo:


tip

If you accidentally delete a ModScript, you can undo this by closing the ModScript panel, then clicking undo in the Level Builder.

Execution Order

I've briefly mentioned execution order, but here's a bit more explanation. Execution order is just the order your ModScripts run in, from the lowest number to the highest.

There are 2 layers of execution order.

  1. The execution order of the MemeItem within the level, relative to other MemeItems. This is set by this number input field at the top right of the ModScript panel:

  1. The execution order of a ModScript within a MemeItem. This is set by this number input field in the explorer:

When you start playing a level, the system goes through every MemeItem in order of execution for the level, and for each MemeItem it comes across, it runs each ModScript in order of execution for that MemeItem. Simple.

Execution order can be negative. It also doesn't have to be unique, but try and make sure two MemeItems don't have the same execution order, or two ModScripts within a MemeItem don't have the same execution order. If they do, make sure code from one of them doesn't rely on the result of code from another, or you might get ambiguous behaviour.


tip

If you want to write a ModScript that isn't necessarily related to a specific MemeItem, just add a dummy MemeItem to your level, maybe like a Meme Text item you can label as something useful.

info

All console output (from using print or error messages) is logged to the in-game console, which can be opened by pressing "Open Console".

This button only shows when your level has a ModScript in it.