Callbacks Component
Component Available | |
Server | Yes |
Client | Yes |
This component allows you to easily trigger server events and get a value returned from it without having to create 3 different events yourself. Simply have to register the Callback on the server and then call it from the Client passing whatever ID you assigned to it.
Required Attributes
Server
RegisterServerCallback: function
Client
ServerCallback: function
Methods
Server
RegisterServerCallback
- Parameters:
event: string, cb: function
- Return:
None
- Description: Registers event ID to function for server callbacks
DoServerCallback
- Parameters:
source: int, event: string, data: any
- Return:
val: any
- Description: Executes registered function associated with given event ID.
Client
ServerCallback
- Parameters:
event: string, data: any, cb: function
- Return:
None
- Description: Calls registered server callback with given event ID.
Events
Server
Callbacks:Server:TriggerEvent
- Sent Values:
event: string, data: any
- Description: Executes function registered to the callback event.
Client
Callbacks:Client:ReceiveCallback
- Sent Values:
event: string, data: any
- Description: Executes function passed to the ServerCallback function to use the value the server returns.
Examples
Below is a simple example of how the callback system works.
Server-Side
exports['bs_base']:FetchComponent('Callbacks'):RegisterServerCallback('Component:Action', function(source, data, cb)
cb(Config.SomeServerValue)
end)
Client-Side
exports['bs_base']:FetchComponent('Callbacks'):ServerCallback('Component:Action', data.character.id, function(value)
print(value)
end)