Link2012 Posted December 7, 2012 Share Posted December 7, 2012 If I use triggerServerEvent, how can I return a success or exit code from the event? The wiki says that to return some stuff I have to use triggerClientEvent, but maybe there's a better way? Link to comment
Mr.T9 Posted December 7, 2012 Share Posted December 7, 2012 triggerServerEvent > Client triggerClientEvent > Server Link to comment
Link2012 Posted December 7, 2012 Author Share Posted December 7, 2012 I understand this, read again my question, my question is the best way to return a exit code from a event, for example: Client GUI sends a event to the server (triggerServerEvent) saying "Hey server, this guy is trying to log with login: leet and password: 1337", if the account doesn't exist the server returns a error code (to the client) and if the accout exists and the login succeeded the server returns a success code. Link to comment
manve1 Posted December 7, 2012 Share Posted December 7, 2012 not sure if there is one, By me Triggering with server/client event function is best way Link to comment
DiSaMe Posted December 7, 2012 Share Posted December 7, 2012 Event triggering and element data are the only ways to send general purpose data. Since they are asynchronous, they require triggering back to get the result. I guess your problem with asynchronous calls is the need to split the triggering and result handling into two functions. It can be solved using coroutines, a way to pause the execution of the function and resume later. You still need to trigger back, but you can continue the execution in the same function which triggered the event. Link to comment
Link2012 Posted December 7, 2012 Author Share Posted December 7, 2012 Event triggering and element data are the only ways to send general purpose data. Since they are asynchronous, they require triggering back to get the result. I guess your problem with asynchronous calls is the need to split the triggering and result handling into two functions. It can be solved using coroutines, a way to pause the execution of the function and resume later. You still need to trigger back, but you can continue the execution in the same function which triggered the event. Your ideia seems good, see this little pseudo-code and tell me if this is the way: -- server.lua function onTryLogin(login, password) -- check login and password code triggerClientEvent("onLoginReturnState", getRootElement(), return_code) end addEvent, bla bla bla -- client.lua coroutine_handle = 0 function onLoginReturnState(return_code) coroutine.resume(coroutine_handle, return_code) end function onButtonLoginClick() -- assume this is a coroutine created somewhere when the button is clicked -- bla bla bla triggerServerEvent("onTryLogin", bla bla bla) exit_code = coroutine.yield() -- check exit code etc end addEvent bla bla bla Link to comment
DiSaMe Posted December 7, 2012 Share Posted December 7, 2012 Yeah, this is what I mean. 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