The SD.Callback module is a specialized utility within the SD library that facilitates the registration and handling of network events and their associated callbacks. This module is designed to improve the robustness and maintainability of scripts by providing a standardized method for handling asynchronous events across client-server communications.


Purpose: Simplifies the handling and triggering of network events from the client side to the server, ensuring that callbacks are managed efficiently and that the system enforces appropriate timing constraints to prevent abuse.


Purpose: Registers a callback for a specific event, setting up the necessary infrastructure to handle the event cleanly and efficiently.


  • _ (any): Unused parameter, typically the self-reference in object-oriented calls.

  • event (string): The event name.

  • delay (number | false): Optional delay to throttle the event.

  • cb (function | false): The callback function to execute when a response is received, or false for a promise-based response.

  • ... (any): Additional arguments to pass to the server event.

Usage Example

-- Triggering a server callback with a delay and handling the response via callback function
SD.Callback('getPlayerData', 500, function(response)
    print('Received player data:', response)
end, playerId)

-- Triggering a server callback with promise-based response handling
local playerData = SD.Callback('getPlayerData', 500, false, playerId)
print('Player data:', playerData)

Last updated