Current Battery Level
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.
- CalixtheGreat
- Regular
- Posts: 72
- Joined: Thu Jun 08, 2017 12:00 am
- Projects: Zephyr Breeze Investigations
- itch: calixthegreat
- Location: Philippines
- Contact:
Current Battery Level
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!
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!
- IrinaLazareva
- Veteran
- Posts: 399
- Joined: Wed Jun 08, 2016 1:49 pm
- Projects: Legacy
- Organization: SunShI
- Location: St.Petersburg, Russia
- Contact:
Re: Current Battery Level
a)current date:
viewtopic.php?f=8&t=37939&p=410599#p410599
b)current battery:
viewtopic.php?f=8&t=37939&p=410599#p410599
b)current battery:
Code: Select all
init python:
import pygame_sdl2
bat = pygame_sdl2.power.get_power_info().percent
label start:
'[bat] %%'
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Current Battery Level
That won't work as expected if placed in a screen, the charge level will never update.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] %%'
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
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
- IrinaLazareva
- Veteran
- Posts: 399
- Joined: Wed Jun 08, 2016 1:49 pm
- Projects: Legacy
- Organization: SunShI
- Location: St.Petersburg, Russia
- Contact:
Re: Current Battery Level
Well, using a python block (especially, the import $ block) inside a screen is not the really good idea... Don't ask, I can't explain because of language barrier.
https://www.renpy.org/doc/html/screens.html#python
https://www.renpy.org/doc/html/screens.html#default
https://www.renpy.org/doc/html/screen_a ... l#Function
Anyway, I have answered the question posed, no more
https://www.renpy.org/doc/html/screens.html#python
https://www.renpy.org/doc/html/screens.html#default
https://www.renpy.org/doc/html/screen_a ... l#Function
Anyway, I have answered the question posed, no more
- PyTom
- Ren'Py Creator
- Posts: 16096
- 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:
Re: Current Battery Level
A python block is fine, import is bad.
Is how I'd do it.
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
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom(When was the last time you backed up your game?)
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:
Re: Current Battery Level
Thanks for the response guys.
Is there a way to show the battery in a bar form instead of numbers? Thank you again!
Is there a way to show the battery in a bar form instead of numbers? Thank you again!
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Current Battery Level
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.
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
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: Current Battery Level
StaticValue would be the bar you want...
On an aside; you could pull pygame_sdl2 from the alias within display.behavior rather than import...
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)
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
Re: Current Battery Level
This should be in a cookbook...
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3794
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Current Battery Level
Thank you for pointing out StaticValue, it helped a lot.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)
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'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
Twitter
pro·gram·mer (noun) An organism capable of converting caffeine into code.
Current project: GGD Mentor
Who is online
Users browsing this forum: Google [Bot], Sugar_and_rice