Can RenPy read the players data? (Name)
Posted: Fri Dec 15, 2017 8:30 am
Inspired by OneShot, Niko asks if your name is (PC USERNAME). I'm trying to figure out if I can do the same sort of thing in my game?
Supporting creators of visual novels and story-based games since 2003.
https://lemmasoft.renai.us/forums/
Code: Select all
label start:
python:
import os
user = os.environ.get('username')
"Hello there, [user]."
Could you elaborate on this? I only get errors.
Code: Select all
## using init doesn't appear to be a requirement, but it makes no difference if I leave it out.
init python:
import os
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
player = os.environ.get(name)
"Hello there, [player]."
Code: Select all
default player = 'Player'
init python:
import os
player = os.environ.get( 'USERNAME',
os.environ.get( 'USER',
os.environ.get( 'LNAME',
os.environ.get( 'LOGNAME', 'Player' ))))
label start:
"Hello there, [player]."
Thanks, but that didn't do as expected.Remix wrote: ↑Mon Jan 22, 2018 8:13 am You have no if/else logic to break the loop once found... suggest:Python .get on dictionary/object = reference.get( attribute, [optional default if key not found] )Code: Select all
default player = 'Player' init python: import os player = os.environ.get( 'USERNAME', os.environ.get( 'USER', os.environ.get( 'LNAME', os.environ.get( 'LOGNAME', 'Player' )))) label start: "Hello there, [player]."
Code: Select all
init python:
if os.name == 'nt':
import os
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
player = os.environ.get(name)
elif os.name == 'posix':
import os
for user in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
player = os.environ.get('USER')
Code: Select all
default player = os.environ.get('username')
label start:
python:
if os.name == 'nt':
import os
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
player = os.environ.get(name)
elif os.name == 'posix':
import os
for user in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
player = os.environ.get('USER')
a "hello [player]"