Jump to content

[HELP] Return values ​​with triggers


Vazern

Recommended Posts

Hello guys!

Does anyone know a way to return values with a trigger, or is there another method?

(I'm trying to completely stop using element-data, but I'm not sure how to return values, just how to set, since the trigger functions only return nil, false, or true)

Link to comment
  1. Trigger a custom event from A to B (e.g. "onRequestAccountDetails")
  2. B handles the event, and calculates a return
  3. Trigger a custom event back from B to A with the return value along it (e.g. "onReceiveAccountDetails")
  4. A handles this as if it were a callback function

You can make your life easier by writing a wrapper that handles this as if it was proper callbacks, keeping a table that maps requests to callback functions, and calls them when the returning event comes, along with the return value.

The other option is coroutines, which, while being a lot more complicated, allow you to pause ("yield") the execution of a script until the return value arrives from the other end, and returns the value as a return of a simple call. This imitates a blocking function, which pauses execution of the Lua script (doesn't freeze the whole client) until the return is available, as opposed to the traditional use of asynchronous functions that work via callbacks.

This is because events are asynchronous, meaning it takes quite a bit of time for the data to travel from the client to the server or vice versa, longer than the execution of one instruction - so you either have to pause execution, or end the function at some point and continue on in a callback handler function when the return is ready.

Edited by Investor
  • Thanks 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...