Check Yesterday's Date

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.
Post Reply
Message
Author
User avatar
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:

Check Yesterday's Date

#1 Post by AoiUsui »

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.

User avatar
Godline
Veteran
Posts: 499
Joined: Fri Jun 27, 2014 12:26 am
Completed: numerous
Tumblr: godlinegames
Deviantart: godline-games
itch: godline
Contact:

Re: Check Yesterday's Date

#2 Post by Godline »

viewtopic.php?t=23829

That might be what you want!

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Check Yesterday's Date

#3 Post by hell_oh_world »

AoiUsui wrote: Wed May 06, 2020 4:46 am 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.

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
Haven't tried, but should work. *I think* :P
Last edited by hell_oh_world on Wed May 06, 2020 6:12 am, edited 1 time in total.

User avatar
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

#4 Post by Imperf3kt »

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

User avatar
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

#5 Post by AoiUsui »

Hi again,
Thank you for your response, will check your suggestion and will definitely update you.

User avatar
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

#6 Post by AoiUsui »

hell_oh_world wrote: Wed May 06, 2020 5:15 am
AoiUsui wrote: Wed May 06, 2020 4:46 am 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.

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
Haven't tried, but should work. *I think* :P
Hi,

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. :D

Post Reply

Who is online

Users browsing this forum: No registered users