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:
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.
a timer on renpy that checks time over the internet
init python:
import requests
import datetime
# get current datetime from site
def get_worldtime():
res = None
try:
# get data from worldtimeapi.org
data = requests.get('http://worldtimeapi.org/api/timezone/Etc/UTC').json()["datetime"]
# convert string to datetime format
res = datetime.datetime.fromisoformat(data)
except requests.RequestException as e:
renpy.notify("Something wrong: " + str(e))
return res
# using sample
def check_time():
world_now = get_worldtime().timestamp()
now = datetime.utcnow().timestamp()
# do what you want
# ***
dt = now - world_now
renpy.notify(str(dt))
label start:
# test
# $ check_time()
# $ t = get_worldtime()
# "[t]"
python:
now = datetime.utcnow().timestamp()
world_now = get_worldtime().timestamp()
dt = now - world_now
$ xxx = str(dt)
"No pause: [xxx]"
python:
now = datetime.utcnow().timestamp()
renpy.pause(2)
world_now = get_worldtime().timestamp()
dt = now - world_now
$ xxx = str(dt)
"With pause: [xxx]"
return