Page 1 of 1

Check Yesterday's Date

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

Re: Check Yesterday's Date

Posted: Wed May 06, 2020 5:03 am
by Godline
viewtopic.php?t=23829

That might be what you want!

Re: Check Yesterday's Date

Posted: Wed May 06, 2020 5:15 am
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

Re: Check Yesterday's Date

Posted: Wed May 06, 2020 5:48 am
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.

Re: Check Yesterday's Date

Posted: Wed May 06, 2020 6:20 am
by AoiUsui
Hi again,
Thank you for your response, will check your suggestion and will definitely update you.

Re: Check Yesterday's Date

Posted: Fri May 08, 2020 1:54 am
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