Below I have my code that handles searching for a user in parse.
The “if” statement runs fine when the text field’s text matches a registered user. However, when the text field’s text doesn’t match a registered user, the “else if” statement should run. However, it doesn’t.
My question is: How can I get the else if statement to run when the text field text doesn’t match a registered user?
I am guessing there is some kind of debugging method to set as the conditional statement, for example: elseif (value.results == nil) or something along those lines that can detect when no users are returned/found. Thanks!
- –search bar function to find user
- local function onSearchUser( ok, res, info )
- if (ok == true) then
- for key, value in ipairs( res.results ) do
- if (value.username == searchInput.text) then
- – user found!
- print(“USER FOUND!”)
- print( "Push notification target is: "…searchInput.text )
- gamesettings.pushNotificationTarget = “”…searchInput.text
- loadsave.saveTable(gamesettings, “settings.json”)
- elseif (value.username ~= searchInput.text) then
- native.showAlert( “No User Found”, searchInput.text…" does not exist!", { “” } )
- end
- end
- end
- end
- parse.macro.findUserByUsername( ‘’…searchInput.text)
- :response(onSearchUser)