Hi,
I am using Corona with GameSparks and I am making a username registrationRequest following this guide on GameSparks.
I made a Module in Corona and created a function using
M.registerUser = function(userName) local result = { status = '', errorMsg = '' } -- Make backend call -- On backend response, set result values ('success' or 'failed') return result end
Then I have a login.lua file that makes a scene with the following function
local function createUserListener(event) if (event.phase == "submitted") then local username = event.target.text local register = authentication.registerUser(username) if (register.status == "success") then -- Great, call function to make new player elseif (register.status == "failed") then -- Failed to register username end end
So the backend is taking longer than the code takes to execute and I’m getting the expected error: register is nil
How do I make the function wait for register to have a value?
Can someone show code example of using callbacks or making an event listener?
I could put the registerUser function in the createUserListener function but I want to be able to use modules.
Thanks.