CreateSignal (Function): Difference between revisions
From Legacy Roblox Wiki
Jump to navigationJump to search
>XLEGOx No edit summary |
m Text replacement - "<SyntaxHighlight code="lua">" to "<syntaxhighlight lang="lua">" |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
<onlyinclude>{{Function | <onlyinclude>{{Function | ||
|name = CreateSignal | |name = CreateSignal | ||
|returns = [[ | |returns = [[RbxUtility (Library)/LuaSignal|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 = 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. | ||
}} | }} | ||
Line 10: | Line 10: | ||
== Description == | == Description == | ||
This function is used to create "custom events" for use in user-code, that act mostly like normal Roblox events. For example: | This function is used to create "custom events" for use in user-code, that act mostly like normal Roblox events. For example: | ||
< | <syntaxhighlight lang="lua"> | ||
local lib = LoadLibrary('RbxUtility') | local lib = assert(LoadLibrary('RbxUtility')) | ||
local sig = lib.CreateSignal() | local sig = lib.CreateSignal() | ||
-- | -- | ||
Line 19: | Line 19: | ||
-- | -- | ||
sig:fire("Hello, World!") --> Makes the event fire, so that all the handlers are called | sig:fire("Hello, World!") --> Makes the event fire, so that all the handlers are called | ||
</ | </syntaxhighlight> | ||
Note that the LuaSignal class also supports all of the other properties of events, such as wait: | Note that the LuaSignal class also supports all of the other properties of events, such as wait: | ||
< | <syntaxhighlight lang="lua"> | ||
Spawn(function() | Spawn(function() | ||
local result = sig:wait() | local result = sig:wait() | ||
Line 27: | Line 27: | ||
end) | end) | ||
sig:fire("Continue Message") --> Makes any waiting code continue, as well as firing connected functions | sig:fire("Continue Message") --> Makes any waiting code continue, as well as firing connected functions | ||
</ | </syntaxhighlight> | ||
==See Also== | ==See Also== |
Latest revision as of 06:19, 27 April 2023
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 = assert(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