In the wiki page of the TriggerEvent() function there is an example for the callbacks usage in events:
-- example of callbacks
local printFunction = Citizen and Citizen.Trace or print
TriggerEvent('myEventWithACallback', function(argument)
printFunction(tostring(argument))
end)
But it happens not to be enough extensive to be able to really understand its usage, or at least that’s my case. Would someone please, either explain a bit how it actually works or show a working example of its usage, or both (that’d be perfect)? I mean, I understand a bit how it works, but I’m trying to get it to work but no luck yet, o that’s why I’m asking for help…
This is what I’ve tried doing so far, without results:
RegisterServerEvent('event')
AddEventHandler('event', function(cb) cb() end) -- also tried doing just cb instead of function(cb) cb() end, but this makes more sense to me, though neither of them work.
TriggerEvent('event', function()
print('foo')
end)
Any help would be appreciated, thanks.