Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
-
CalixtheGreat
- Regular
- Posts: 72
- Joined: Thu Jun 08, 2017 12:00 am
- Projects: Zephyr Breeze Investigations
- itch: calixthegreat
- Location: Philippines
-
Contact:
#1
Post
by CalixtheGreat » Mon Nov 05, 2018 8:18 am
Good day!
Just want to ask if it's possible to show the current battery level of your PC/phone in the game? I also want to include the current date but I don't know how. I already have the real time clock shown on my game.
Sorry for my English Hahah. Thanks in advance!

-
Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
-
Contact:
#3
Post
by Imperf3kt » Tue Nov 06, 2018 5:05 am
IrinaLazareva wrote: ↑Mon Nov 05, 2018 10:57 am
b)current battery:
Code: Select all
init python:
import pygame_sdl2
bat = pygame_sdl2.power.get_power_info().percent
label start:
'[bat] %%'
That won't work as expected if placed in a screen, the charge level will never update.
I did something extremely similar not too long ago:
Code: Select all
screen ancilliary():
python:
import pygame_sdl2
battery_level = pygame_sdl2.power.get_power_info().percent
zorder 1000
vbox:
xalign 0.99
yalign 0.01
text "{color=#000}{size=18}Battery:[battery_level]%{/size}{/color}"
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project:
GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
-
PyTom
- Ren'Py Creator
- Posts: 15893
- Joined: Mon Feb 02, 2004 10:58 am
- Completed: Moonlight Walks
- Projects: Ren'Py
- IRC Nick: renpytom
- Github: renpytom
- itch: renpytom
- Location: Kings Park, NY
-
Contact:
#5
Post
by PyTom » Tue Nov 06, 2018 11:30 pm
A python block is fine, import is bad.
Code: Select all
init python:
import pygame_sdl2
screen ancilliary():
python:
battery_level = pygame_sdl2.power.get_power_info().percent
zorder 1000
vbox:
xalign 0.99
yalign 0.01
text "Battery:[battery_level]% color "#000" size 18
Is how I'd do it.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama •
https://www.patreon.com/renpytom
-
CalixtheGreat
- Regular
- Posts: 72
- Joined: Thu Jun 08, 2017 12:00 am
- Projects: Zephyr Breeze Investigations
- itch: calixthegreat
- Location: Philippines
-
Contact:
#6
Post
by CalixtheGreat » Wed Nov 07, 2018 12:36 am
Thanks for the response guys.
Is there a way to show the battery in a bar form instead of numbers? Thank you again!
-
Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
-
Contact:
#7
Post
by Imperf3kt » Wed Nov 07, 2018 12:48 am
Appreciate the explanation, Pytom, IrinaLazareva. I'll remember it from now on.
CalixtheGreat, you could use a bar, I forget it's exact name.
I'm working on this too, so I'll share whatever I come up with tonight.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project:
GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
-
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:
#8
Post
by Remix » Wed Nov 07, 2018 7:32 am
StaticValue would be the bar you want...
On an aside; you could pull pygame_sdl2 from the alias within display.behavior rather than import...
Code: Select all
screen power_status():
$ pwr = renpy.display.behavior.pygame.power.get_power_info()
fixed:
area (0.85, 0.0, 0.15, 0.1)
fixed:
pos (0,0)
bar value StaticValue(value=float(pwr.percent)/100.0, range=1.0)
if pwr.state == 4: ## you could test the other numbers for 'unplugged', 'low battery' etc
text "charging" pos (0,0)
# add "on_charge.png" pos (20,0)
if pwr.seconds > 0:
text "[pwr.seconds] seconds until fully charged" pos (0,30)
-
Alex
- Lemma-Class Veteran
- Posts: 2981
- Joined: Fri Dec 11, 2009 5:25 pm
-
Contact:
#9
Post
by Alex » Wed Nov 07, 2018 12:18 pm
This should be in a cookbook...

-
Imperf3kt
- Lemma-Class Veteran
- Posts: 3636
- Joined: Mon Dec 14, 2015 5:05 am
- Location: Your monitor
-
Contact:
#10
Post
by Imperf3kt » Wed Nov 07, 2018 3:58 pm
Remix wrote: ↑Wed Nov 07, 2018 7:32 am
StaticValue would be the bar you want...
On an aside; you could pull pygame_sdl2 from the alias within display.behavior rather than import...
Code: Select all
screen power_status():
$ pwr = renpy.display.behavior.pygame.power.get_power_info()
fixed:
area (0.85, 0.0, 0.15, 0.1)
fixed:
pos (0,0)
bar value StaticValue(value=float(pwr.percent)/100.0, range=1.0)
if pwr.state == 4: ## you could test the other numbers for 'unplugged', 'low battery' etc
text "charging" pos (0,0)
# add "on_charge.png" pos (20,0)
if pwr.seconds > 0:
text "[pwr.seconds] seconds until fully charged" pos (0,30)
Thank you for pointing out StaticValue, it helped a lot.
I came up with something before you posted, but it wasn't working right using Value, do I substituted StaticValue in its place and now it works perfect!
I am curious about your comment in this line though:
Code: Select all
if pwr.state == 4: ## you could test the other numbers for 'unplugged', 'low battery' etc
I am unable to find these numbers you speak of.
I'm tempted to substitute random numbers and see what happens, but it'd be easier with documentation.
Edit:
I think I found it:
https://wiki.libsdl.org/SDL_GetPowerInfo
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project:
GGD Mentor
Free Android GUI - Updated occasionally
Twitter
Imperf3kt Blackjack - a WIP blackjack game for Android made using Ren'Py
Users browsing this forum: No registered users