Jump to content

triggerServerEvent - returning a code


Link2012

Recommended Posts

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

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
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

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...