A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!
This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
-
Andredron
- Miko-Class Veteran
- Posts: 535
- Joined: Thu Dec 28, 2017 2:37 pm
- Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
- Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
- Location: Russia
-
Contact:
#1
Post
by Andredron » Wed Jan 24, 2018 7:26 pm
Sorry for my terrible English!
Good afternoon. Made a timer that works even if the user does not sign in the project. Тhe information was taken from here
https://python-scripts.com/datetime-time-python Here is the code:
Code: Select all
init python:
import datetime
label splashscreen:
scene black
if not persistent.my_time:
$ persistent.my_time = datetime.datetime.today()
else:
$ a = datetime.datetime.today()
$ delta = a - persistent.my_time
$ seconds = delta.total_seconds()
$ hours = seconds // 3600
centered "It's been [seconds] seconds since the previous pressing."
return
screen test_scr():
textbutton "Press!" action SetField(persistent, "my_time", datetime.datetime.today()) align(0.5, 0.05)
# The game starts here.
label start:
show screen test_scr
"..."
e "You've created a new Ren'Py game."
e "Once you add a story, pictures, and music, you can release it to the world!"
return
Here the check is made during startup of the game (in the splashscreen ). It remains only not to forget to store the new value into persistent variables before closing the game...
Last edited by
Andredron on Thu Jan 25, 2018 5:01 pm, edited 1 time in total.
-
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:
#2
Post
by PyTom » Wed Jan 24, 2018 8:34 pm
Here's my version of it.
Code: Select all
init python:
import time
default persistent.last_time = time.time()
default persistent.money = 10
define MONEY_PER_SECOND = 100 / 3600.0 # 100 per hour.
init python:
class CashIn(Action):
def __call__(self):
now = time.time()
if now < persistent.last_time:
return
change = (now - persistent.last_time) * MONEY_PER_SECOND
persistent.money += change
persistent.last_time = now
renpy.show_screen("got_money", change=change, total=persistent.money )
renpy.restart_interaction()
screen got_money(change, total):
modal True
frame:
xalign 0.5
yalign 0.5
text "You just got [change:.2f] moneys. You have [total:.2f] moneys total."
null height 20
textbutton "Cool." action Hide("got_money")
screen cash_button():
vbox:
text "Wallet: [persistent.money:.2f] money."
textbutton "Cash In" action CashIn()
label start:
screen black
show screen cash_button
"You can click the button to cash in now."
return
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
-
Andredron
- Miko-Class Veteran
- Posts: 535
- Joined: Thu Dec 28, 2017 2:37 pm
- Completed: Kimi ga nozomu renpy-port(demo), Albatross Koukairoku(demo)
- Projects: Sisters ~Natsu no Saigo no Hi~(renpy-port)
- Location: Russia
-
Contact:
#3
Post
by Andredron » Tue Jan 07, 2020 3:24 am
Users browsing this forum: No registered users