tes3scriptContext⚓︎
A script context object, which allows variables to be get/set using the variable name.
Example: An example of indexing local script variables inside tes3scriptContext
objects
Companions usually have a mwscript script with variable named companion
set to 1. This can be used to determine if a reference is player's companion or not.
--- This function returns `true` if the reference
--- has a variable companion set to 1 in its script.
---@param reference tes3reference
---@return boolean
local function hasCompanionShare(reference)
-- Any local script variable inside `tes3scriptContext`
-- objects can be read as if it were a normal Lua table
-- (`reference.context` is of `tes3scriptContext` type)
local companion = reference.context.companion
-- or:
-- local companion = reference.context["companion"]
-- In addition, local script variables can be accessed from the tes3npc object:
-- myNpc.script.context.somVarName
-- To change the variable value, do an assignment:
-- reference.context.companion = 0
return (
companion and
companion == 1 or
false
)
end
Properties⚓︎
[string]
⚓︎
Read-only. This allows indexing a local script variable by it's name. The variable's value can be read or modified this way. There is an example at the top of the page on doing this.
Returns:
result
(number, nil)
Methods⚓︎
getVariableData
⚓︎
This method fetches all of the script's variables as a table.
local results = myObject:getVariableData()
Returns:
results
(table<string, tes3scriptVariableData>): A table with all of the script's variable names as keys.
Math Operations⚓︎
Length (#
)⚓︎
Result type | Description |
---|---|
number | Returns the total amount of variables in this tes3scriptContext. |