The reason why you have to use a capital ‘N’ in user N ame inside user n ame, is because of the fact that you just defined username as a local text object, and then you are trying to set it as its own text which is the reason why username is nil. As @roaminggamer said, Corona is case-sensitive, plus it is simple logic.
Reference to the code I sent you, and it should work.
Remember, username(text object) cannot use username as text. Call the display object userNameText to prevent confusion, and the code should work out fine.
To clear things up:
local userName local userNameText userNameText = display.newText(userNameText, ......) screenGroup:insert(userName)
Lua variable names *are* case sensitive. username and userName are different variables. However, they are so close, it’s too easy to mix them up. You should use descriptive variable names in particular when there is room for confusion. In this case I would:
username – The text string being sent to or received from online.
usernameTextField – the native.newTextField() object used to allow the user to input a user name
usernameTextDisplay – the display.newTextObject that will display the user name on the screen when it’s just being shown (not the input object)
usernameLabel – A display.newTextObject() with the word “Username” used with the native.newTextField() to instruct the user what the field is for.
As for other things, you need to take the time and try and read the error message and break it down. It gives you a line number and a description of the problem.
error loading module 'profile' from file 'C:\Users\user\Documents\Corona Projects\app\profile.lua': C:\Users\user\Documents\Corona Projects\app\profile.lua:29: unexpected symbol near '.'
What is line 29 of profile.lua? We can’t help you with out knowing that and the code around it. But you have a period where it’s not expected. Maybe you need a comma there, it’s easy to mix a period (.) and comma (,) up.
The other thing is you frequently don’t try what your being asked to try. Saying “that didnt’ work” doesn’t help us help you. You need to provide what the current message, and show us how you changed your code.
I don’t see that error there anymore so nit’s not an issue .
I tried your code :
local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") -- forward declare the text fields local json = require("json") local userName local userNameText local function networkListener( event ) if ( event.isError ) then local alert = native.showAlert( "Error Loading .", "Check your internet connection .", { "Try again" } ) end end function scene:create(event) local screenGroup = self.view local background = display.newImageRect("insta.jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) local userNameText = display.newText(userNameText, 200, 200) --notice the capital 'N' screenGroup:insert(userName) end
and I got this error :
bad argument #1 to 'newText' (string expected, got nil) stack traceback: [C]: in function 'newText' C:\Users\user\Documents\Corona Projects\app\profile.lua:28: in function '?' ?: in function 'dispatchEvent' ?: in function 'gotoScene' C:\Users\user\Documents\Corona Projects\app\newsfeed.lua:42: in function '\_onPress' ?: in function '\_setSelected' ?: in function '?' ?: in function \<?:182\>
--Wrong local userNameText = display.newText(userNameText, 200, 200) --notice the capital 'N' screenGroup:insert(userName) --Right local userNameText = display.newText(userName, 200, 200) --notice the capital 'N' screenGroup:insert(userName)
local userName local userNameText function scene:create(event) local screenGroup = self.view local background = display.newImageRect("insta.jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) local userNameText = display.newText(userName, 100, 200, native.systemFont, 16 ) --\<------ take the "local" off here, you have it local near the top myText:setFillColor( 1, 0, 0 ) screenGroup:insert(userName) --\<----- you cannot insert a string into a group. This should be userNameText end
Do you want it to show the user name of the person who owns the device?
Do you want to get a list of all users or some group of users and give the device owner the ability to see a list of users?
If it’s the first option, why not save the username locally and display it from your local information. You have a login process so you could keep the username they logged in with locally.