Lua: Difference between revisions

From SigMod
Jump to navigation Jump to search
mNo edit summary
m (Updated github links for lua files in the == Setting up in VS Code == section)
 
(3 intermediate revisions by 2 users not shown)
Line 6: Line 6:


Mission lua scripts are managed by [[Custom Entities#$script manager|$script_manager]] entity with popscript targetname   
Mission lua scripts are managed by [[Custom Entities#$script manager|$script_manager]] entity with popscript targetname   
All mission and $script_mananger scripts are in a global scope and can access each other 


scripts/globals.lua is always parsed before mission scripts
scripts/globals.lua is always parsed before mission scripts
Line 13: Line 15:
==== [https://github.com/rafradek/sigsegv-mvm/blob/master/scripts/mvm_bigrock_luademo.pop '''Example popfile'''] ====
==== [https://github.com/rafradek/sigsegv-mvm/blob/master/scripts/mvm_bigrock_luademo.pop '''Example popfile'''] ====


==== [https://github.com/rafradek/sigsegv-mvm/blob/master/src/lua/globals.lua globals.lua] ====
==== [https://github.com/rafradek/sigsegv-mvm/blob/master/scripts/globals.lua globals.lua] ====


==== [https://github.com/rafradek/sigsegv-mvm/blob/master/src/lua/library.lua library.lua] ====
==== [https://github.com/rafradek/sigsegv-mvm/blob/master/scripts/library.lua library.lua] ====


== Setting up in VS Code ==
== Setting up in VS Code ==
Install Lua extension in marketplace. Place [https://github.com/rafradek/sigsegv-mvm/blob/master/src/lua/globals.lua globals.lua] and [https://github.com/rafradek/sigsegv-mvm/blob/master/src/lua/library.lua library.lua] in the directory where you want to create lua scripts, and load them in VS Code. This will enable autocompletion for your lua scripts
Install Lua extension in marketplace. Place [https://github.com/rafradek/sigsegv-mvm/blob/master/scripts/globals.lua globals.lua] and [https://github.com/rafradek/sigsegv-mvm/blob/master/scripts/library.lua library.lua] in the directory where you want to create lua scripts, and load them in VS Code. This will enable autocompletion for your lua scripts


== Profiling ==
== Profiling ==
It is possible to measure script performance with sig_lua_prof_start and sig_lua_prof_end client commands
It is possible to measure script performance with sig_lua_prof_start and sig_lua_prof_end client commands

Latest revision as of 07:03, 11 December 2022

It is possible to embed Lua scripts into missions with LuaScript / LuaScriptFile keys.

The scripts are parsed once when the game switches a mission, or when the map reset vote is called

Lua programming guide is available at https://www.lua.org/pil/1.html and a quick reference at https://www.lua.org/manual/5.4/

Mission lua scripts are managed by $script_manager entity with popscript targetname

All mission and $script_mananger scripts are in a global scope and can access each other

scripts/globals.lua is always parsed before mission scripts

scripts/library.lua contains function definitons provided by the game library

Example popfile[edit | edit source]

globals.lua[edit | edit source]

library.lua[edit | edit source]

Setting up in VS Code[edit | edit source]

Install Lua extension in marketplace. Place globals.lua and library.lua in the directory where you want to create lua scripts, and load them in VS Code. This will enable autocompletion for your lua scripts

Profiling[edit | edit source]

It is possible to measure script performance with sig_lua_prof_start and sig_lua_prof_end client commands