How simple do you need?
Trust me, I get it. Something someone else finds simple, can look hard when you first see it.
The solution is to experiment. Write it wrong, write it wrong again and keep going until you find something you are happy with (or give up).
Every example I've written about time of day type solutions... I'd write differently.
So let's go really simple...
Python:
default dnc = 0
default cycle = "Morning"
define daynight_list = ["Morning", "Afternoon", "Evening"]
init python:
def advance_dnc():
store.dnc += 1
store.dnc %= 3
store.cycle = daynight_list[store.dnc]
return
label start:
"*** START ***"
label the_loop:
menu:
"It's currently [cycle]."
"Advance":
$ advance_dnc()
"Exit":
jump the_end
jump the_loop
label the_end:
"*** THE END ***"
return
So a little explanation:
I use
define
to create variables that will never change (while the script is running) and
default
for variables that WILL change.
[
and
]
are used to create a
You must be registered to see the links
. (see my signature for more reading too).
def advance_dnc():
within a
init python:
block, just lets me create a new python function to do something. In this case to "advance the day-night-cycle".
var1 += 1
adds 1 to an existing variable called
var1
.
var2 += 6
would add 6.
var1 %= 3
does a
You must be registered to see the links
calculation (in this case, mod 3). Also see
You must be registered to see the links
.
Okay... that one is going to need a bit more explaining.
a = x mod y
returns the remainder when
x
is divided by
y
and stores it in
a
.
You probably use modulo every day without thinking about it when you look at a clock in the afternoon (mod 12).
new_hour = hour % 12
... 13:00 is 1pm, 14:00 is 2pm. 13 / 12 = 1 remainder 1. 14 / 12 = 1 remainder 2.
In this case, lists within python start to be numbered at 0 and we want "Morning", "Afternoon" and "Evening". 3 periods of time. 0, 1, 2. When we get to 3 (that is 2 + 1 = 3), we want it too loop back to 0. Modulo is great for this.
But I could have written:
Python:
if store.dnc > 2:
store.dnc = 0
I prefixed variables with
store.
within the python function to avoid RenPy/python assuming where the variable is kept. Variables within python scripts can be local or global. Prefixing stuff with
store.
removes all doubt (and is often required).
Implementing this within your game would only require you to add a
$ advance_dnc()
line anywhere the player does something which would advance the day/night cycle.
There are ways to write the same code without using python functions using
def
, but they would require using a different mechanism
call
and return
- which is in theory simpler - but I've seen TOO many new RenPy programmers screw up. So much so, I was tempted to not even mention it.
Here are some more complicated solutions. Some allow for 12 hours per day and keeping track of if it's Monday, Tuesday, etc.
https://f95zone.to/threads/renpy-time-advance-issue.35438/post-2695277
https://f95zone.to/threads/resetting-variables-based-on-variable-value-issue.59667/
https://f95zone.to/threads/have-an-...now-how-to-write-the-code.75796/#post-5848292