Vazern Posted December 15, 2018 Share Posted December 15, 2018 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
Investor Posted December 15, 2018 Share Posted December 15, 2018 (edited) Trigger a custom event from A to B (e.g. "onRequestAccountDetails") B handles the event, and calculates a return Trigger a custom event back from B to A with the return value along it (e.g. "onReceiveAccountDetails") 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 December 15, 2018 by Investor 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now