Ren'Py Very simple hour and day system for Renpy

Hot Soup

New Member
Game Developer
Mar 5, 2019
9
12
Hello guys,

I'm a new dev and I've just started learning code using Renpy. So I'm a REAL noob.
I've read several threads about creating an hour/week system, I tried to copy/paste some code but as much as I try I can't get nothing to work. I've spent hours with this and it's getting frustrating.

I just need a really simple system:

Daytime: Morning, Afternoon, Evening and Night.
Week: Mon, Tue, Wed, Thu, Fri, Sat, Sun.
And a button to pass from one daytime to another.

And where exactly to put the code in script.rpy and screens.rpy

I'm sorry if I'm the 999 guy to ask about this and if I seem lazy or something, but trust me, I've been trying for hours and I can't get it.

Thank you and sorry if my english gets a bit crappy!
 

V.A. Laurie

Game Writer & Editor
Game Developer
Oct 9, 2017
557
1,875
I write words, not code... Well not much code. I may not give good advice here but...

I would think you set a variable to represent day, another for the time.

The button to switch between times could activate a function that would essentially say "if morning, set time as afternoon. If afternoon, set time as evening, etc. If night, set time as morning and advance day."

The day function would do similarly, checking which day it is, then going to the next.

I have no idea what the cleanest way to do this would be, but a sloppy version should be fairly easy.
 

Penfold Mole

Engaged Member
Respected User
May 22, 2017
3,118
7,618
You could set numeric values to days and daytimes (monday=1, tuesday=2, ... sunday=7, morning=1, afternoon=2, ... night=4) and then use increment for increasing the value of both variables up to maximum value. The only "if" you need would set the variable from its maximum value back to the minimum.
Less work and would look nicer.
 
Last edited:

Quintillian

Member
Apr 15, 2019
124
239
You could set numeric values to days and daytimes (monday=1, tuesday=2, ... sunday=7, morning=1, afternoon=2, ... night=4) and then use increment for increasing the value of both variables up to maximum value. The only "if" you need would set the variable from its maximum value back to the minimum.
Less work and would look nicer.

I know I am late, but just writing this in case someone else stumbles upon this. To add to what Penfold Mole said, a good way to keep the values cycling without the need of "if statements" is with the implementation of the module operand. For example, whenever an hour increases by one the following line of code will keep the values within the allowed margin.

Python:
hourOfDay = (hourOfDay + 1) % 24
 
  • Like
Reactions: Penfold Mole

Penfold Mole

Engaged Member
Respected User
May 22, 2017
3,118
7,618
Python:
hourOfDay = (hourOfDay + 1) % 24
Neat! (y)
Any cycle of numbers can be constructed the same way. For example, two lines of code:
Python:
weekDay = (weekDay + (hourOfDay + 1) / 24) % 7
hourOfDay = (hourOfDay + 1) % 24
Would increase weekDay by one just before hourOfDay gets zeroed from 23.
 
Last edited:
  • Like
Reactions: Quintillian

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,611
2,258
My solution was this. The thread was about showing things on the screen, but I wrote a date/time system as an example.
Though now I've read a couple of the links posted already, I would probably incorporate some of the ideas in those threads.