Menu
Lumberyard
Legacy Reference

Common Lua Globals and Functions

CryLua is deprecated and will be removed in a future version of Lumberyard.
  • File location: Game/Scripts/common.lua

  • Loaded from: Game/Scripts/main.lua

Globals

Use the following globals to avoid temporary Lua memory allocations:

Name

Description

g_SignalData_point Basic 3D vector value used by g_SignalData.
g_SignalData_point2 Basic 3D vector value used by g_SignalData.
g_SignalData Used to pass signal data in AI behavior scripts. See Signals.
g_StringTemp1 Commonly used for temporary strings inside Lua functions.
g_HitTable Commonly used by the Physics.RayWorldIntersection function.

A g_HitTable used with Physics.RayWorldIntersection can contain the following parameters:

Parameter

Description

pos 3D vector world coordinates of the ray hit.
normal 3D normal vector of the ray hit.
dist Distance of the ray hit.
surface Type of surface hit.
entity Script table of entity hit (if one was hit).
renderNode Script handle to a foliage or static render node.

A g_SignalData table can contain the following parameter types:

Type

Description

Vec3 3D vector.
ScriptHandle Normally used to pass along an entity ID.
Floating Point Floating point value.
Integer Integer or number value.
String String value.

AIReload()

Reloads the aiconfig.lua Lua script (Game/Scripts/AI/).

AIDebugToggle()

Toggles the ai_DebugDraw console variable on and off.

ShowTime()

Logs the current system time to the console. Format is Day/Month/Year, Hours:Minutes.

count()

Returns the number of key-value pairs in a given table.

Parameter Description
_tbl Table to retrieve the number of key-value pairs from.

new()

Creates a new table by copying an specified existing table. This function is commonly used to create a local table based on an entity parameter table.

Parameter Description
_obj Existing table you want to create a new one from.
norecurse Flag indicating whether or not to recursively recreate all sub-tables. If set to TRUE, sub-tables will not be recreated.

merge()

Merges two tables without merging functions from the source table.

Parameter Description
dst Destination table to merge source table information into.
src Source table to merge table information from.
recurse Flag indicating whether or not to recursively merge all sub-tables.

mergef()

Merges two tables including merging functions from the source table.

Parameter Description
dst Destination table to merge source table information into.
src Source table to merge table information from.
recursive Flag indicating whether or not to recursively merge all sub-tables.

Vec2Str()

Converts a 3D vector table into a string and returns it in the following format: (x: X.XXX y: Y.YYY z: Z.ZZZ).

Parameter Description
vec 3D vector table to convert. Example: {x=1,y=1,z=1}.

LogError()

Logs an error message to the console and the log file. Message appears in red text in the console.

Parameter Description
fmt Formatted message string.
... Optional argument list. For example: LogError("MyError: %f", math.pi);

LogWarning()

Logs a warning message to the console and the log file. Message appears in yellow text in the console.

Parameter Description
fmt Formatted message string.
... Optional argument list. For example: LogWarning("MyError: %f", math.pi);

Log()

Logs a message to the console and the log file. Commonly used for debugging purposes.

Parameter Description
fmt Formatted message string.
... Optional argument list. For example: Log("MyLog: %f", math.pi);

dump()

Dumps information from a specified table to the console.

Parameter Description
_class Table to dump to console. For example: g_localActor
no_func Flag indicating whether or not to dump the table functions.
depth Depth of the tables tree dump information from.

EmptyString()

Checks whether or not a given string is set and its length is greater than zero. Returns TRUE or FALSE.

Parameter Description
str String to check for.

NumberToBool()

Checks whether or not a number value is true (non-zero) or false (zero).

Parameter Description
n Number to check for.

EntityName()

Retrieves the name of a specified entity ID or entity table. If the entity doesn't exist, this function returns an empty string.

Parameter Description
entity Entity table or entity ID to return a name for.

EntityNamed()

Checks whether or not an entity with the specified name exists in the entity system. Returns TRUE or FALSE. Commonly used for debugging.

Parameter Description
name Name of entity to check for.

SafeTableGet()

Checks whether or not a sub-table with a specified name exists in a table. If the sub-table exists, this function returns it; otherwise the function returns nil.

Parameter Description
table Table to check for the existence of a sub-table.
name Sub-table name to check for.