Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Event (type): Difference between revisions

From FiguraMC
No edit summary
No edit summary
Line 1: Line 1:
The event type is used for events such as <code>events.TICK</code>. To create an event function, use one of the following.
The event type is used for events such as <code>events.TICK</code>. To create an event function, use one of the following.


<syntaxHighlight lang="lua">
<syntaxHighlight lang="lua"> local tick = 0
function events[EVENT]()
function events.WORLD_TICK()
  tick = tick + 1
end
end
-- OR
-- OR
events[EVENT]:register(function()
local tick = 0
end) -- optionally as a name argument to allow removal
events.WORLD_TICK:register(function()
  tick = tick + 1
end, "TICK_COUNTER")
</syntaxHighlight>
</syntaxHighlight>


Line 15: Line 18:
! | Description
! | Description
|-
|-
| remove
| [[/remove|remove]]
| Takes in a [https://lua.org/manual/5.1/manual.html#5.4 string] with the name of the event, and removes it, stopping it from being called
| Takes in a [https://lua.org/manual/5.1/manual.html#5.4 string] with the name of the event, and removes it, stopping it from being called
|-
|-
| clear
| [[/clear|clear]]
| Clears the event of all methods
| Clears the event of all methods
|-
|-
| register
| [[/register|register]]
| Takes in a [https://www.lua.org/manual/5.1/manual.html#2.5.9 function] to run when the event is fired, with an optional name argument ([https://lua.org/manual/5.1/manual.html#5.4 string])
| Takes in a [https://www.lua.org/manual/5.1/manual.html#2.5.9 function] to run when the event is fired, with an optional name argument ([https://lua.org/manual/5.1/manual.html#5.4 string])
|-
|-
| getRegisteredCount
| [[/getRegisteredCount|getRegisteredCount]]
| Returns the amount of functions registered, with an optional name argument ([https://lua.org/manual/5.1/manual.html#5.4 string])
| Returns the amount of functions registered, with an optional name argument ([https://lua.org/manual/5.1/manual.html#5.4 string])
|}
|}
== Fields ==
remove:
# name : [https://lua.org/manual/5.1/manual.html#5.4 string]
register:
# function : [https://www.lua.org/manual/5.1/manual.html#2.5.9 function]
# name : [https://lua.org/manual/5.1/manual.html#5.4 string] (optional)
getRegisteredCount:
# name : [https://lua.org/manual/5.1/manual.html#5.4 string] (optional)

Revision as of 18:11, 26 September 2024

The event type is used for events such as events.TICK. To create an event function, use one of the following.

 local tick = 0
function events.WORLD_TICK()
  tick = tick + 1
end
-- OR
local tick = 0
events.WORLD_TICK:register(function()
  tick = tick + 1
end, "TICK_COUNTER")

Methods

Method Description
remove Takes in a string with the name of the event, and removes it, stopping it from being called
clear Clears the event of all methods
register Takes in a function to run when the event is fired, with an optional name argument (string)
getRegisteredCount Returns the amount of functions registered, with an optional name argument (string)
Contents