Writing Lua for Dream Editor Projects

Our game engine uses Lua to build game logic. Lua is a widely-used lightweight scripting system focused on speed and ease-of-use. Lua is widely documented and googling “How do I do X in Lua” usually returns useful results.

Install VS Code

To write lua scripts you should first install Visual Studio Code, an excellent, free, cross-platform code editor. When installing VS Code, be sure to check the “Add ‘Open with Code’ to Windows Explorer” option, as it will make your life easier in the future.

You may have a preferred code editor; but we only support our DreamEditor extension for VS Code.

  1. Download and install VS Code.
  2. Next, install the Funovus Lua extension. (See: Lua Plugin Setup)
  3. Finally, install and set up the StyLua extension. (See: Formatting with StyLua)

We also recommend Code Spell Checker (or a similar alternative).

Next we’re going to modify VS Code’s file associations so it recognizes our trigger files as Lua script. You can likely skip this step if you have the DreamEditor extension added to VS Code as it should setup the file extensions automatically. The DreamEditor extension is automatically installed and updated whenever you install a new version of the editor. You can check if you already have installed in the “Extensions” icon in VS Code.

https://user-images.githubusercontent.com/56179276/162342352-c0b98fa1-b0f3-4435-9f07-ae1d4f8e9d37.png

To manually set up your file associations, go to “File > Preferences > Settings”. Then on the left go to “Text Editor > Files”. Finally, under “Associations” click “Add Item”. On the Item box write "*.lua.txt“, and on Value write”lua", without quotation marks.

It should now look like this:

https://user-images.githubusercontent.com/56179276/162342103-592e543b-a3cf-41d3-81d3-ea048b3c6423.png

Alternatively, you add this to settings.json via

"files.associations": {
    "*.lua.txt": "lua"
}

Be sure to read and follow our Lua Style Guide!