Page 1 of 1
How do I get the user's username?
Posted: Thu Apr 28, 2022 10:59 pm
by Algumber
I wanted to make a little horror game thing, where in one part, it shows the username of the player (the username on his computer), how do I do that?
Re: How do I get the user's username?
Posted: Fri Apr 29, 2022 7:39 am
by MrFariator
Simplest method I know of is
Code: Select all
os.getenv("USERNAME") -- gets the currently logged username
os.getenv("USERPROFILE") -- gets the location of the user profile, eq. C:\Users\xyz
However, I'm not sure how cross-platform this is. For other approaches you could call some system functions via FFI.
Re: How do I get the user's username?
Posted: Fri Apr 29, 2022 8:18 pm
by pgimeno
On Linux it's os.getenv("USER"). I guess it's the same on OSX. Can't tell for iOS/Android.
Re: How do I get the user's username?
Posted: Sat Apr 30, 2022 10:48 pm
by Gunroar:Cannon()
os.getenv("USER") and others above return nil for Android. Does it even have a feature like that?
Re: How do I get the user's username?
Posted: Sun May 01, 2022 6:47 am
by GVovkiv
Gunroar:Cannon() wrote: ↑Sat Apr 30, 2022 10:48 pm
os.getenv("USER") and others above return nil for Android. Does it even have a feature like that?
probably because android doesn't have local accounts system
as i can understand, it's single user os, so no "USER" variable for you
Re: How do I get the user's username?
Posted: Sun May 01, 2022 12:01 pm
by Gunroar:Cannon()
I suspect the same for IOS.