Time/day system
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.
Time/day system
Hello guys!
First of all I want to say sorry for my bad english I hope you understand.
So, I'm new renpy user, also I'm studying Python but I think that the code I'm going to use is pretty hard for my knowledges.
So what I need is a time/day/ system
I want the time changes when an event is triggered, something like (if go to bed time set to 00:00)
I've solved this point by using a code made by trooper6 viewtopic.php?f=51&t=21978#p279023 found in the cookbook, I'm using the digital clock, that's very cool, also I can see the animation of the time flowing.
The problem is that I want that everytime the time is 00:00 a new day starts.
So I want a variable called day that everytime the time is 00:00 increases by 1.
So I can count the days
I'm pretty sure that I need a loop (while) but I don't know how to set that
Can you please help me?
First of all I want to say sorry for my bad english I hope you understand.
So, I'm new renpy user, also I'm studying Python but I think that the code I'm going to use is pretty hard for my knowledges.
So what I need is a time/day/ system
I want the time changes when an event is triggered, something like (if go to bed time set to 00:00)
I've solved this point by using a code made by trooper6 viewtopic.php?f=51&t=21978#p279023 found in the cookbook, I'm using the digital clock, that's very cool, also I can see the animation of the time flowing.
The problem is that I want that everytime the time is 00:00 a new day starts.
So I want a variable called day that everytime the time is 00:00 increases by 1.
So I can count the days
I'm pretty sure that I need a loop (while) but I don't know how to set that
Can you please help me?
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Time/day system
Is your game going to be running in real time, or will you be adding time whenever the player does an action?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Re: Time/day system
Hi trooper6 thanks for that code in the cookbook
Yes I will add time when the player does action
Yes I will add time when the player does action
- Potato0095
- Regular
- Posts: 84
- Joined: Sun May 08, 2016 8:40 pm
- Projects: LoveCraft
- itch: potato95
- Location: Brazil
- Contact:
Re: Time/day system
You could use a division floor rounded number + 1 as the day counter. It will depend on your code, however, the logic is the same nonetheless.
e.g: 71 hours divided by 24 will give you 2.95833... Rounding to the floor number and adding 1, 3rd day. 73 hours will give you 3.04166... It's the 4th day.
Edit:
Of course, you can remove the python block and use $ before both of them as this code is very tiny.
If you want to check Python statements inside Ren'Py, check the Documentation:
https://www.renpy.org/doc/html/python.html
Edit 2:
Fixed the logic, instead of "day = a / 24", it's "day = a / 24 + 1"
Code: Select all
python:
a = 0 # "a" being the number of hours, you'll set this variable at any moment inside your code.
day = int(a / 24) + 1 # you'll get a float number. You'll get the day you're in if the integer rounds the number to the floor and adds 1.
Edit:
Of course, you can remove the python block and use $ before both of them as this code is very tiny.
If you want to check Python statements inside Ren'Py, check the Documentation:
https://www.renpy.org/doc/html/python.html
Edit 2:
Fixed the logic, instead of "day = a / 24", it's "day = a / 24 + 1"
Last edited by Potato0095 on Tue Mar 03, 2020 3:06 am, edited 2 times in total.
"There are two types of lies: Lies that hurt, and lies that don't."
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Time/day system
I don't think it would be that hard to change the code to work for your needs.
I have a big deadline this coming Friday. Let me look into the code and see what sort of changes I can make over the weekend.
I have a big deadline this coming Friday. Let me look into the code and see what sort of changes I can make over the weekend.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Re: Time/day system
Thanks for the answer Potato0095 and trooper6
Right now I'm trying something like that under, but that doesn't work
I made this code but probably I'm doing something wrong ç_ç because the day doesn't increase, that is always 1
Thanks trooper6 I'm studying a lot of python and renpy code cause I'm new to programming
Right now I'm trying something like that under, but that doesn't work
Code: Select all
self.days = 1 #This is the day I want to start with
@property
def day(self):
return self.days #This method gives me the day
def advance(self, i=0):
if h == 0: # H stands for hours
i = i + 1 # i is the increment I used in the while loop
while i > 0:
self.days = self.days + 1 # if i = 1 self.days increas by 1
i -= 1 # the I set (i) back to 0 to restart the cycle
Thanks trooper6 I'm studying a lot of python and renpy code cause I'm new to programming
- Potato0095
- Regular
- Posts: 84
- Joined: Sun May 08, 2016 8:40 pm
- Projects: LoveCraft
- itch: potato95
- Location: Brazil
- Contact:
Re: Time/day system
First, I want to apologize. My previous logic had a fault. It didn't give the int = day, it was giving "yesterday", so you would need to use:
Now, onto the second matter. It's untested, but you could work something with this if needed:
The usage inside Ren'Py of this code would be:
$ checkday(the_number_of_hours) # this will automatically return the day to you, no other action is needed, just using the counter.
You could assign a variable to each action, and then, when needed, get the day through this function. In other words, you could have a variable called "hours", and replacing this:
With this:
Then assigning the correct number of hours in this variable and running the function like "$ checkday()" would save you a lot of time.
Edit1:
E.g: If you open the console on Ren'Py and use checkday(24) on the first code, it will give you "2". If you assign hours and use checkday() on the latter, it will give you the correct day automatically.
Code: Select all
day = int(a / 24) + 1
Code: Select all
init python:
import renpy.store as store
class Day(store.object):
def __init__(self, day):
self.day = day
def checkday(h): # $ checkday(h)
day = int(h / 24) + 1
return day
$ checkday(the_number_of_hours) # this will automatically return the day to you, no other action is needed, just using the counter.
You could assign a variable to each action, and then, when needed, get the day through this function. In other words, you could have a variable called "hours", and replacing this:
Code: Select all
def checkday(h): # $ checkday(h)
day = int(h / 24) + 1
return day
Code: Select all
def checkday(): # $ checkday()
day = int(hours / 24) + 1
return day
Edit1:
E.g: If you open the console on Ren'Py and use checkday(24) on the first code, it will give you "2". If you assign hours and use checkday() on the latter, it will give you the correct day automatically.
"There are two types of lies: Lies that hurt, and lies that don't."
- Potato0095
- Regular
- Posts: 84
- Joined: Sun May 08, 2016 8:40 pm
- Projects: LoveCraft
- itch: potato95
- Location: Brazil
- Contact:
Re: Time/day system
Hm... maybe it's on "if h == 0", it'll only run i = i + 1 if it is 0. I don't think this is the correct logic, but you're getting there.iDweadith wrote: ↑Mon Mar 02, 2020 9:06 pm Thanks for the answer Potato0095 and trooper6
Right now I'm trying something like that under, but that doesn't work
I made this code but probably I'm doing something wrong ç_ç because the day doesn't increase, that is always 1Code: Select all
self.days = 1 #This is the day I want to start with @property def day(self): return self.days #This method gives me the day def advance(self, i=0): if h == 0: # H stands for hours i = i + 1 # i is the increment I used in the while loop while i > 0: self.days = self.days + 1 # if i = 1 self.days increas by 1 i -= 1 # the I set (i) back to 0 to restart the cycle
Thanks, trooper6 I'm studying a lot of python and renpy code cause I'm new to programming
A note, however. You should start to write "i += 1" (just like you did with "i -=1") instead of "i = i + 1". It adds 1 no matter what, it's just esthetic and the "normal" thing to do when you code.
"There are two types of lies: Lies that hurt, and lies that don't."
Re: Time/day system
Ok, thanks
I have a problem using your code, because on the clock system that I'm using, once h > than 23 it resets back to 0.
Something like:
So I can't do like (48/24 + 1) for the day 3, and I get stuck on day 2
I have a problem using your code, because on the clock system that I'm using, once h > than 23 it resets back to 0.
Something like:
Code: Select all
if h > 23:
h = h%24
So I can't do like (48/24 + 1) for the day 3, and I get stuck on day 2
- Potato0095
- Regular
- Posts: 84
- Joined: Sun May 08, 2016 8:40 pm
- Projects: LoveCraft
- itch: potato95
- Location: Brazil
- Contact:
Re: Time/day system
Oh, you're using trooper6's code, I kind of forgot about that, this would've made this easier (or not). Sorry, both of you. Now, let's get to work. I won't add the whole code here, you can use ctrl + f to find specific parts of the code where I add things and change there. I assume you're using the digital clock (please say you do or said this before and I don't remember), so I'll work with that.iDweadith wrote: ↑Tue Mar 03, 2020 8:08 pm Ok, thanks
I have a problem using your code, because on the clock system that I'm using, once h > than 23 it resets back to 0.
Something like:Code: Select all
if h > 23: h = h%24
So I can't do like (48/24 + 1) for day 3, and I get stuck on day 2
Trooper6 can correct me if I'm wrong (I usually am), but we could add a self.hours and a self.days to the variables, just for the sake of precise control over our self.days (I mess up when I use minutes or seconds to count days).
Code: Select all
#Variables for handling time
self.days = 1
self.hours = self.minutes/60
self.minutes = (h*60)+m # max minutes in a day are 1440
Code: Select all
def render(self, width, height, st, at):
# How many days have passed
if self.hours > 23:
self.days += int(self.hours / 24.1 + 1) # As I said before, the logic is the same nonetheless
"There are two types of lies: Lies that hurt, and lies that don't."
Re: Time/day system
Thanks a lot for the help
So I tried your code the logic I think is right but dunno why it isn't working for me.
I mean, I did some test and self.hours always gives me 0
While self.minutes gives me the expected value but never reaches 1440 due to the reset
So I tried your code the logic I think is right but dunno why it isn't working for me.
I mean, I did some test and self.hours always gives me 0
While self.minutes gives me the expected value but never reaches 1440 due to the reset
- Potato0095
- Regular
- Posts: 84
- Joined: Sun May 08, 2016 8:40 pm
- Projects: LoveCraft
- itch: potato95
- Location: Brazil
- Contact:
Re: Time/day system
Did you misspell anything, or didn't put anything in the right part of the document? Check if your "if self.hours > 23:" statement is inside the "def render". You don't need to create one, use the one already in the code. Check your indentation, your code should be like this:
If this doesn't work, it's out of my scope, I wouldn't understand why it isn't working and would start to put that if statement anywhere I would think it would work, like on the digital render (below else) and such.
Code: Select all
def render(self, width, height, st, at):
if self.seconds_target:
if self.forward:
#Advances the seconds variable until it is the same as the seconds_target variable
if self.seconds_target > self.seconds:
self.seconds += self.step
#Resets the seconds_target variable
if self.seconds_target <= self.seconds:
self.seconds_target = 0
else:
if self.seconds_target < self.seconds:
self.seconds -= self.step
if self.seconds_target >= self.seconds:
self.seconds_target = 0
self.forward = True
if self.hours > 23:
self.days += int(self.hours / 24.1 + 1) # As I said before, the logic is the same nonetheless
#Makes sure the minutes variable is always in sync with the seconds variable
if self.minutes != self.seconds//60:
self.minutes = self.seconds//60
# Calculating how many seconds have passed today.
if self.seconds >= 86400:
self.seconds -= 86400
if self.seconds_target:
self.seconds_target -= 86400
elif self.seconds < 0:
self.seconds += 86400
if self.seconds_target:
self.seconds_target += 86400
If this doesn't work, it's out of my scope, I wouldn't understand why it isn't working and would start to put that if statement anywhere I would think it would work, like on the digital render (below else) and such.
"There are two types of lies: Lies that hurt, and lies that don't."
Re: Time/day system
My code is the same as yours up there
I'm still trying but nothing
I'm still trying but nothing
- trooper6
- Lemma-Class Veteran
- Posts: 3712
- Joined: Sat Jul 09, 2011 10:33 pm
- Projects: A Close Shave
- Location: Medford, MA
- Contact:
Re: Time/day system
IDwedith, I’m going to look into recoding my clock to include a day marker, but I can’t do it until this weekend. But I’ll look into it!
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?) Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978
Re: Time/day system
Thanks trooper6 I'll wait then.
Also I'm learning many things these days.
Also I'm learning many things these days.
Who is online
Users browsing this forum: Ocelot