Events
loadbuffer
Called when Lua code is about to be loaded and executed. Can be used to modify, block, or replace the code before execution.
Parameters
name: string- Name/identifier of the chunk being loadedcontent: string- The Lua code content to be executedmode: string- Load mode ('t' for text, 'b' for binary, 'bt' for both)
Returns
boolean | string | nil- Return true to block execution, return a string to replace the code, or return nil to allow normal execution
Example
Autorun.on("loadbuffer", function(name, content, mode) -- Your event handler code hereend)Custom Events
Section titled “Custom Events”You can create and trigger your own custom events using Autorun.trigger().
-- Trigger a custom eventAutorun.trigger("myCustomEvent", arg1, arg2, arg3)
-- Listen to the custom eventAutorun.on("myCustomEvent", function(arg1, arg2, arg3) Autorun.print("Custom event triggered!", arg1, arg2, arg3)end)Remote Events
Section titled “Remote Events”Remote events can be created that will be sent to the opposite realm (client <-> menu).
Listen to them with Autorun.onRemote(eventName, callback) and trigger them with Autorun.triggerRemote(eventName, value).
Note that, unlike traditional events, since this runs across states, you cannot send state-sensitive values, ie functions, userdata, etc.
The current supported types are:
- nil
- boolean
- number
- string
In the future basic tables will be supported.
Example
Section titled “Example”-- Send a message to the menu when client initializesAutorun.triggerRemote("clientGreeting", "hi")
-- Optional: Listen for responses from menuAutorun.onRemote("menuResponse", function(message) print("Menu says: " .. message)end)-- Listen for messages from the clientAutorun.onRemote("clientGreeting", function(message) print("Client says: " .. message)
-- Optional: Send a response back Autorun.triggerRemote("menuResponse", "hello from menu!")end)