What is Lua?
Lua is an extension programming language that is widely used as a scripting language in applications. Due to its simple syntax, it is used in games such as Garry's Mod, World of Warcraft, Far Cry and many more.
Within Natural Selection 2, the majority of the game code will be written in Lua.
As well as providing a convenient environment for the NS2 team to code in, it will allow users to create modifications of the game.
|Warning: The documentation of Lua within Natural Selection 2 is far from complete. Information may be incorrect and its reliability of data should not be trusted.|
Example: Key Input
local function SendKeyEvent(key, down) if key == InputKey.Q and down then Shared.Message('Hello World') end end Event.Hook("SendKeyEvent", SendKeyEvent)
There are four URL-style path prefixes available to Lua scripts:
- The base game directory (ns2) with active mod directories laid on top. Scripts cannot write to this directory.
- The per-user config directory, located within the current Windows user profile.
- The directory in which pathing data and compiled shaders are stored. In current builds it's inside the config directory.
- Unknown location.
Printing to the console
The standard Lua print() function doesn't print to the game console. Use one of these instead:
- Prints to the console without decoration.
- Prints to the console with the name of the current VM and a timestamp.