comm
Functions:
expose_func
comm.expose_func(function_name: string, callback: function): boolean
function_name
string
Function name to expose
callback
function
Lua function to call
Exposes the specified function of current script to the shared environment so that other scripts can call it. Returns false on failure.
unexpose_func
comm.unexpose_func(function_name: string): boolean
function_name
string
Function name to unexpose
Unexposes the specified function of current script. Returns false on failure.
call_func
comm.call_func(script_name: string, function_name: string[, ...]): any
script_name
string
Script name to communicate
function_name
string
Function name to call
...
any
Optional. Parameters to pass to the function.
Calls the specified function of the specified script. Returns the return value of the function, if any.
Example:
local function greet(name)
return "Hello " .. name .. ". From test1.lua."
end
comm.expose_func("greet", greet)
local num1 = 1
local num2 = 2
local function add()
num1 = num1 + num2
end
comm.expose_func("add", add)events.player:set("PlayerJoinEvent", function(e)
local greeting = comm.call_func("test1.lua", "greet", e.player:getName())
print(greeting) -- prints "Hello xxx. From test1.lua"
comm.call_func("test1.lua","add")
-- Every time a player joins, num1 will be added to num2 in test1.lua
end)Last updated
