BeamNG uses two type of Virtual Machines: one for the Game Engine and one per vehicles.

Modules that are in the common folder and C++ bindings are available for both.

Debugging & Testing

There are different ways to test your Lua scripts in

In this article we describe how you can test Lua commands or use them for scenarios.

Debugging via Console:

To open the Console press the ~ (tilde) key on keyboards with US layout.

For different keyboard layouts, verify which key is assigned to the Toggle System Console action in the Options > Controls > Bindings menu, under the General Debug section

Lua Terms

  • Array: A Lua table that contains only integer keys from 1 to infinity. Can be counted correctly with #tbl
  • Dictionary (dict): A lua table that contains all kinds of keys. Cannot be counted with #tbl.
  • Module: The traditional Lua module is deprecated. Do not use it
  • Package: the normal Lua package. Used, but please use Extensions if possible. See here and also here.
  • Extensions: BeamNG’s module system. Includes serialization, events and Lifetime management.

Lua Syntactic Sugar

tabl.ident is equivalent to tabl['ident']
v:name(args) is syntactic sugar for,args)
func{fields} is syntactic sugar for func({fields})
func'string' (or func"string" or func[[string]]) is syntactic sugar for func('string')
function t.a.b.c:foobar(params) body end is syntactic sugar for t.a.b.c.foobar = function(self, params) body end

Lua code style

  • Folder naming example: ge/someFolderHere/lowerCamelCase/
  • File naming example: lowerCamelCase.lua
  • Indenting: 2 spaces (not tabs)
  • Trim trailing spaces ON
  • Function and variable names, camelCase
  • "Class" names, upper camel case (PascalCase), example: MyCoolClass
Page created: 21 March 2021, at 11:22
Last modified: 17 April 2021, at 17:12

Any further questions?

Join our discord