It is called scoping you code is read from top to bottem. If you call a local function before it is declared you will get it an error
Your code you supplied above has two functions:
local function userRegister( event ) local function networkListener( event )
and I’m giving you a 3rd function you need:
local function urlencode( str )
In Lua/Corona the order of functions matter. userRegister tries to call networkListener (via. the network.request call), but networkListener doesn’t exist at that point, so nil gets passed to the handler. Your network.request() will never execute the call back. Your functions have to be in this order:
local function urlencode( event ) local function networkListener( event ) local function userRegister( event )
Technically urlencode and networkListener could swap order, but networkListener absolutely has to be defined in your code before userRegsiter.
Rob
I am getting this error
register.lua:24: attempt to call global 'url\_encode' (a nil value) stack traceback: C:\Users\user\Documents\Corona Projects\app\register.lua:24: in func tion '\_onEvent' ?: in function '?' ?: in function \<?:449\> ?: in function \<?:221\>
That function is not build inhttps://coronalabs.com/blog/2014/11/11/tutorial-encoding-urls-for-network-usage/Put it on top
My mistake, take out the _ in url_ecode.
Rob
Thanks it works , but I did this
local function networkListener( event ) if ( event.isError ) then print( "Network error. ") else if event.response == "success" then print("Success! We are now registered!") -- put the code here to go to where the user needs to be -- after a successful registration composer.gotoScene("login") else -- put code here to notify the user of the problem, perhaps -- a native.alert() dialog that shows them the value of event.response -- and take them back to the registration screen to let them try again local alert = native.showAlert( "You are not connected to the Internet. ", { "Try again"}, onComplete ) end end end
And it’s not taking me to the login page , but the info is going to the database (sign up is successful)
If you don’t get success you cannot assume they are not connect to the internet.
But the info gets sent to the database . Doesn’t that mean the it’s connected to the internet
No. If you get a “user exists”, you’re connected to the Internet just fine. The user needs to use a different username and/or email
You have lots of other echos like if the user already exists or passwords don’t match you should show those errors to the user.
What I don’t get is , when I click register the information gets sent to database correctly but the screen doesn’t go to the login page and the console says something went wrong . try again
can you copy and paste the message from the console log to here?
Something went wrong. Try again.
that is not an error message, what does your corona logs say
I’m not getting any errors that’s all it says
Can you post a screen shot?
Corona opens up a console log. It’s a white window behind your simulator. Please copy and paste the message from there.
Yeah that’s all it shows Something went wrong. Try again.
please post screen shot of where you are seeing this.