Function
Use the function requirement in a KubeJS recipe
A function requirement is a way to execute javascript code when a recipe is processing.
To do that 2 things are needed :
A method that will tell the recipe to send a KubeJS event when needed.
An event listener where the JS code will be put.
Both the recipe method and the event listener are linked using a String id.
Note: This has nothing to do with MC functions (or commands), this requirement allow you to make your own code in JavaScript and pass it to be executed by the machine.
In the recipe
The passed id MUST be a string.
Several functions can share the same id, but they will all share the same event too.
The function can be delayed, put
.delay(delay)
directly after any.requireFunctionXXX()
call to make the function be executed at the specified delay.
In a server script (outside the recipe event)
If neither
event.success()
norevent.error()
are called the recipe will be allowed to run.If
event.error()
is called without specifying an error message it will show the default one instead.The
event
object contains several useful methods, see more on its dedicated wiki page.
Example :
Migrating from previous function requirement
Previously :
Now :
Last updated