How do I get the user's username?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How do I get the user's username?
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?
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: How do I get the user's username?
Simplest method I know of is
However, I'm not sure how cross-platform this is. For other approaches you could call some system functions via FFI.
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
Re: How do I get the user's username?
On Linux it's os.getenv("USER"). I guess it's the same on OSX. Can't tell for iOS/Android.
- Gunroar:Cannon()
- Party member
- Posts: 1139
- Joined: Thu Dec 10, 2020 1:57 am
Re: How do I get the user's username?
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?
probably because android doesn't have local accounts systemGunroar: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?
as i can understand, it's single user os, so no "USER" variable for you
- Gunroar:Cannon()
- Party member
- Posts: 1139
- Joined: Thu Dec 10, 2020 1:57 am
Re: How do I get the user's username?
I suspect the same for IOS.
Who is online
Users browsing this forum: Google [Bot] and 4 guests