Documentation
  • 👋Introduction
  • 📚Guides
    • Useful Links
  • 🆓boii_utils
    • Installation
    • Configuration
    • Modules
    • API
      • Callbacks
      • Characters
      • Commands
      • Cooldowns
      • Debugging
      • Entities
      • Environment
      • Framework Bridge
      • Geometry
      • Items
      • Keys
      • Licences
      • Maths
      • Methods
      • Player
      • Requests
      • Strings
      • Tables
      • Timestamps
      • UI Bridges
      • Vehicles
      • Version
      • XP
      • UI Elements
Powered by GitBook
On this page
  • Accessing the Module
  • Server
  • register_callback(name, cb)
  • Parameters
  • Example
  • Client
  • trigger_callback(name, data, cb)
  • Parameters
  • Example
  1. boii_utils
  2. API

Callbacks

The Callbacks module provides a standalone, framework-agnostic system for registering and triggering callbacks between the client and server.


Accessing the Module

local CALLBACKS <const> = exports.boii_utils:get("modules.callbacks")

Server

register_callback(name, cb)

Registers a server-side callback that clients can trigger.

Parameters

Name
Type
Description

name

string

The unique identifier for the callback event.

cb

function

The function to execute when the callback is triggered.

Example

CALLBACKS.register("get_server_time", function(source, data, cb)
    local response = {
        unix = os.time(),
        hour = GetClockHours()
    }
    cb(response)
end)

Client

trigger_callback(name, data, cb)

Triggers a server-side callback and handles the result asynchronously.

Parameters

Name
Type
Description

name

string

The event name to trigger.

data

table

Optional data to send to the server.

cb

function

Callback function to handle the response. Signature: function(response)

Example

CALLBACKS.trigger("get_server_time", nil, function(response)
    print("Unix time:", response.unix)
    print("In-game hour:", response.hour)
end)
PreviousAPINextCharacters

Last updated 1 month ago

🆓