Skip to content

Scripting introduction

SDraw edited this page Jun 5, 2023 · 16 revisions

Before to start

  • Learn Lua
  • Download CVRLua_Editor.unitypackage from latest release
  • Import into your world project
  • Add LuaScript component to your GameObject(s)

LuaScript has three lists:

  • Variables list: Contains entries that will be executed as single line of Lua code as <Variable Name> = <Variable Value>.
  • VariableObjects list: Contains entries where object will be assigned to global variable with specified name.
    • WARNING: Do not add objects of types that don't have implemented Lua bindings.
  • Scripts list: This list contains TextAssets that will be executed as Lua scripts in specified order upon LuaScript component awakening. Scripts can contain Lua code in plain text or binary compiled through luac.

Example of filled LuaScript component:
2023-05-26_23-38-55

Your first script

Let's create simple script:

function Start()
    Log("Hello, "..localPlayer.name.."!")
end

Since Unity accepts specific file types to be reconginzed as TextAsset, let's save our script as HelloWorld.lua.txt anywhere in project. Now add it into scripts list of your LuaScript component, upload your world and you're done.

Enjoy not yet fully completed but working scripting!