Show users username

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)

:lol: I wish.

I love that after Ed specifically typed out:

I think you effectively latch onto the parts that make sense to you and that you are interested in while the rest drops by the wayside.

the guy’s very next question doesn’t address anything in Ed’s post and just asks:

why do I have to use a capital N in userName ?

Luckily for the rest of us, Ed cannot be disheartened so easily :slight_smile:

I asked in reference to my question, I just hope I tries out my code. 

“Luckily for the rest of us, Ed cannot be disheartened so easily :-)”

I’m very glad this is the case.

Just to be clear:

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.

Rob

Post your profile.lua code and mark line number 29.

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

Uhhhhhhh, you are making the same mistake:

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

Also, you are missing some parameters for the display text.

Please read this tutorial:

https://docs.coronalabs.com/api/library/display/newText.html

It will give the proper syntax.

This is what I have :

 local userNameText = display.newText(userName, 100, 200, native.systemFont, 16 ) myText:setFillColor( 1, 0, 0 ) screenGroup:insert(userName)

and I’m getting the same error 

Where does userName get it’s value?

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 ) myText:setFillColor( 1, 0, 0 ) screenGroup:insert(userName) end
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

You insert display objects into groups.  

You need to give userName an actual value, for example:

local userName = "comeUp264"

Then, it will work.

And what Rob said:

screenGroup:insert(userNameText)

Okay it works . But how do I make it show any users user name and not just mine ?

To do this, you would have to retrieve the name from a list if you make one. I can’t help too much with this, so start a new topic on it.

Where do you expect the username to come from?

My Mysql php database . I have it setup with my PHP . My app is connected to the database 

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.

How do I do that ?