CreateSignal (Function)

From Legacy Roblox Wiki
Revision as of 03:55, 27 April 2023 by Realjame (talk | contribs) (Text replacement - "<code lua>" to "<SyntaxHighlight code="lua">")
Jump to navigationJump to search
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: <SyntaxHighlight code="lua"> 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: <SyntaxHighlight 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

See Also