In Miniworld: Creata, the game provides a special API called ScriptSupportEvent:registerEvent. This API is used to register new events in the game that your Lua script can listen to and respond to.
The function ScriptSupportEvent:registerEvent is used to bind a specific game event to a Lua function, so that whenever the event occurs in the game, the corresponding Lua function gets executed. This allows you to create event-driven behavior in your scripts.
Syntax:
ScriptSupportEvent:registerEvent(EventName, FunctionToExecute)
The “Game.Start” event is triggered whenever the game starts. You can use this event to run code when the game begins. In this case, the event does not pass any parameters to the function.
ScriptSupportEvent:registerEvent("Game.Start", function() print("The game has started!") end)
In this example, every time the game starts, the message “The game has started!” will be printed.
The “Player.ClickBlock” event is triggered whenever a player clicks on a block in the game. When this event is fired, it passes a table as a parameter to the function, which contains the following information:
Example:
ScriptSupportEvent:registerEvent("Player.ClickBlock", function(eventData) local objid = eventData.eventobjid local x = eventData.x local y = eventData.y local z = eventData.z local blockid = eventData.blockid print("Player clicked block at position:", x, y, z, "with block ID:", blockid) end)
In this case, every time a player clicks on a block, it will print the coordinates and the block ID to the console.
ScriptSupportEvent:registerEvent is specific to Miniworld: Creata and is not part of standard Lua.
It takes two arguments: the event name (string) and the function to execute. Different events pass different types of parameters to the function. For “Game.Start”, no parameters are passed. For “Player.ClickBlock”, a table with details about the block is passed. By using this API, you can make your scripts respond to various game events dynamically, allowing you to create more interactive and responsive game behavior.