CreateSignal (Function): Difference between revisions
From Legacy Roblox Wiki
Jump to navigationJump to search
>JulienDethurens No edit summary |
>XLEGOx No edit summary |
||
Line 7: | Line 7: | ||
{{clear floats}} | {{clear floats}} | ||
</onlyinclude> | </onlyinclude> | ||
== Description == | |||
This function is used to create "custom events" for use in user-code, that act mostly like normal Roblox events. For example: | |||
<code lua> | |||
local lib = LoadLibrary('RbxUtility') | |||
local sig = lib.CreateSignal() | |||
-- | |||
sig:connect(function(message) | |||
print("Message: "..tostring(message)) | |||
end) | |||
-- | |||
sig:fire("Hello, World!") --> Makes the event fire, so that all the handlers are called | |||
</code> | |||
Note that the LuaSignal class also supports all of the other properties of events, such as wait: | |||
<code lua> | |||
Spawn(function() | |||
local result = sig:wait() | |||
print("Result: "..tostring(result)) | |||
end) | |||
sig:fire("Continue Message") --> Makes any waiting code continue, as well as firing connected functions | |||
</code> | |||
==See Also== | ==See Also== |
Revision as of 05:20, 9 February 2012
CreateSignal( ) | |
Returns | LuaSignal |
Description: | Returns a LuaSignal object which acts much like the real RBXScriptSignal objects, which ROBLOX events use, only implemented in-Lua for full control from within scripts. |
Description
This function is used to create "custom events" for use in user-code, that act mostly like normal Roblox events. For example:
local lib = LoadLibrary('RbxUtility')
local sig = lib.CreateSignal()
--
sig:connect(function(message)
print("Message: "..tostring(message))
end)
--
sig:fire("Hello, World!") --> Makes the event fire, so that all the handlers are called
Note that the LuaSignal class also supports all of the other properties of events, such as wait:
Spawn(function()
local result = sig:wait()
print("Result: "..tostring(result))
end)
sig:fire("Continue Message") --> Makes any waiting code continue, as well as firing connected functions