Variables

A Lua variable is a name with an associated value.

Variables are declared and assigned values using the = operator.

local name = "Tracy"

The variable scope is determined by whether the variable is declared as local or global.

  • All variables are considered global unless explicitly declared as a local. Global variables are accessible throughout the entire Translator script.

  • A local variable is limited to the block or function wherein it was declared.

In the screenshot below you can see an example of variable scope: Within the variableFunction Using trace() function, we can view the values of both the local and global variables. The scope of the local variable is restricted to the variable function and is not traceable in main.

This leads into the concept of Value Types as we see the local variable returned nil instead of the string “I am local“.

 

Related pages