Hi,
It's been a while.
Would like to know if there is a way in Ren'Py to check the date yesterday even if the game was not opened yesterday? My goal, give the player a bonus whenever he/she plays everyday.
Looking forward for any help.
Check Yesterday's Date
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.
- hell_oh_world
- Miko-Class Veteran
- Posts: 777
- Joined: Fri Jul 12, 2019 5:21 am
- Contact:
Re: Check Yesterday's Date
Code: Select all
label before_main_menu:
python:
from datetime import date
if not persistent.date_before:
persistent.date_before = date.today()
date_today = date.today()
day_difference = (date_today - persistent.date_before).days
persistent.date_before = date.today()
if day_difference < 1:
# no bonus, since the 24 mark didn't pass yet
elif day_difference == 1:
# bonus, since the game is played yesterday
else:
# no bonus, since the game is not played for more than a day
Last edited by hell_oh_world on Wed May 06, 2020 6:12 am, edited 1 time in total.
- Imperf3kt
- Lemma-Class Veteran
- Posts: 3791
- Joined: Mon Dec 14, 2015 5:05 am
- itch: Imperf3kt
- Location: Your monitor
- Contact:
Re: Check Yesterday's Date
You may need to check the time against an internet source, rather than the player's local computer, since local time can be manipulated to take advantage of it.
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
- AoiUsui
- Regular
- Posts: 42
- Joined: Mon Nov 26, 2012 11:21 am
- Completed: Alice's Dolls
- Projects: Alice's Dolls, Tappy Virus
- Organization: Otaku Brigade
- itch: otakubrigade
- Location: Philippines
- Contact:
Re: Check Yesterday's Date
Hi again,
Thank you for your response, will check your suggestion and will definitely update you.
Thank you for your response, will check your suggestion and will definitely update you.
- AoiUsui
- Regular
- Posts: 42
- Joined: Mon Nov 26, 2012 11:21 am
- Completed: Alice's Dolls
- Projects: Alice's Dolls, Tappy Virus
- Organization: Otaku Brigade
- itch: otakubrigade
- Location: Philippines
- Contact:
Re: Check Yesterday's Date
Hi,hell_oh_world wrote: ↑Wed May 06, 2020 5:15 amHaven't tried, but should work. *I think*Code: Select all
label before_main_menu: python: from datetime import date if not persistent.date_before: persistent.date_before = date.today() date_today = date.today() day_difference = (date_today - persistent.date_before).days persistent.date_before = date.today() if day_difference < 1: # no bonus, since the 24 mark didn't pass yet elif day_difference == 1: # bonus, since the game is played yesterday else: # no bonus, since the game is not played for more than a day
Tried this code but encountered some issues. Dealt with it by changing the day_difference to persistent.day_difference.
As for the internet time, the game is designed for offline use. And as much as possible, I want it to be simple.
For the usage of days of the week, I think there will be an issue. Example, I opened the game on Friday the I reopen it in on the Saturday next week.
Thank you very much for your assistance. Very very grateful.
Who is online
Users browsing this forum: No registered users