Can RenPy read the players data? (Name)
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
-
- Newbie
- Posts: 1
- Joined: Fri Dec 15, 2017 8:22 am
- Contact:
Can RenPy read the players data? (Name)
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?
- TheJerminator15
- Regular
- Posts: 161
- Joined: Fri Mar 18, 2016 2:37 pm
- Completed: A Sedentary Fist
- Projects: Manipulation, Switch Swap, Unnamed Project
- itch: jamsandwich
- Location: England
- Contact:
Re: Can RenPy read the players data? (Name)
I don't know how to implement it myself, but it definitely is possible. Doki Doki literature Club is a very recent example of a Ren'Py game using that.
My Current Writing Project: viewtopic.php?f=47&t=37699
Manipulation Teaser Demo: https://drive.google.com/open?id=0BzJ4E ... zV6TWVaclk
Manipulation Teaser Demo: https://drive.google.com/open?id=0BzJ4E ... zV6TWVaclk
- RicharDann
- Veteran
- Posts: 286
- Joined: Thu Aug 31, 2017 11:47 am
- Contact:
Re: Can RenPy read the players data? (Name)
This seems to work on Windows at least:
Code: Select all
label start:
python:
import os
user = os.environ.get('username')
"Hello there, [user]."
The most important step is always the next one.
- xavimat
- Eileen-Class Veteran
- Posts: 1461
- Joined: Sat Feb 25, 2012 8:45 pm
- Completed: Yeshua, Jesus Life, Cops&Robbers
- Projects: Fear&Love
- Organization: Pilgrim Creations
- Github: xavi-mat
- itch: pilgrimcreations
- Location: Spain
- Discord: xavimat
- Contact:
Re: Can RenPy read the players data? (Name)
Tested on Linux (Ubuntu 16.04), and it shows "None" as the user.
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)
- Ocelot
- Lemma-Class Veteran
- Posts: 2438
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Can RenPy read the players data? (Name)
On Linux enviroment variable is named "user".
YOu can detect Windows by checking for os.name() == 'nt'. Linux and MacOS would be os.name() == 'posix'
YOu can detect Windows by checking for os.name() == 'nt'. Linux and MacOS would be os.name() == 'posix'
< < insert Rick Cook quote here > >
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3808
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Can RenPy read the players data? (Name)
Could you elaborate on this? I only get errors.
I use the following, which works great on Windows, but on Linux (Debian), it still returns "None" as username.
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]."
I found this if its related?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
- Contact:
Re: Can RenPy read the players data? (Name)
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]."
Frameworks & Scriptlets:
- Speech Bubble dialogue system
- Multiple Notify with ATL and history
- (WIP) Radial Masking - needs updating to use Shader
- 7.4 - Smooth Tinting using ATL and matrixcolor
- Several other repositories there too
- Ocelot
- Lemma-Class Veteran
- Posts: 2438
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Can RenPy read the players data? (Name)
Yes. I messed up and added brackets. os.name is a string, not function.
< < insert Rick Cook quote here > >
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3808
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Can RenPy read the players data? (Name)
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]."
I didn't particularly want to hijack the thread, but for anyone else who may stumble across this in the future (because stackexchange was proving useless) here's what I found works:
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')
Also do not default the name "player" as that happens after the init takes place, so it overwrites whatever it should show with what you "default"ed it to.
I use this in a screen, but I see no reason it won't work in dialogue as well.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
-
- Newbie
- Posts: 8
- Joined: Fri Aug 17, 2018 7:08 pm
- Projects: Roses Of Love
- Organization: KagariSoft
- Github: Neyunse
- itch: KagariSoft
- Location: Argentina
- Contact:
Re: Can RenPy read the players data? (Name)
to make it detect the name in windows in this way
sorry for my English
sorry for my English
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]"
----------------------------------------------------
My Twitter: @Neyunse
My Discord: ねゆんせ#7916
----------------------------------------------------
KagariSoft Twitter: @KagariSoft
My Discord Server
My Twitter: @Neyunse
My Discord: ねゆんせ#7916
----------------------------------------------------
KagariSoft Twitter: @KagariSoft
My Discord Server
Who is online
Users browsing this forum: No registered users