How do I get the user's username?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Algumber
Prole
Posts: 5
Joined: Tue Mar 08, 2022 10:39 pm

How do I get the user's username?

Post 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?
this post is about stuff

(Itch.io account: https://exotic-toast.itch.io/)
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: How do I get the user's username?

Post 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.
User avatar
pgimeno
Party member
Posts: 3655
Joined: Sun Oct 18, 2015 2:58 pm

Re: How do I get the user's username?

Post by pgimeno »

On Linux it's os.getenv("USER"). I guess it's the same on OSX. Can't tell for iOS/Android.
User avatar
Gunroar:Cannon()
Party member
Posts: 1139
Joined: Thu Dec 10, 2020 1:57 am

Re: How do I get the user's username?

Post by Gunroar:Cannon() »

os.getenv("USER") and others above return nil for Android. Does it even have a feature like that?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
GVovkiv
Party member
Posts: 684
Joined: Fri Jan 15, 2021 7:29 am

Re: How do I get the user's username?

Post 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
User avatar
Gunroar:Cannon()
Party member
Posts: 1139
Joined: Thu Dec 10, 2020 1:57 am

Re: How do I get the user's username?

Post by Gunroar:Cannon() »

I suspect the same for IOS.
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests