Ren'Py Day/Time system

CrimsonAxisStudio

Member
Game Developer
Nov 7, 2017
271
1,558
Hello,

I'm currently working on a visual novel/light open world type game. Essentially, I want to be able to have a day and time system that I can have certain events happen and advance the story. Once these events are finished, I want to be able to advance to the next time slot. AKA: Meet person in morning, talk, scene ends, advance to noon.

I've ready quite a few threads both here and on the lemmesoft forums, but I can't seem to get any of them to work. I'm not sure if Renpy has changed since these posts (2017/2018) or I'm just failing to implement them correctly.

I would post links to the threads I've tried, but I am unable to due to never having posted before and I am restricted until I have 3 approved posts.

If anyone can direct me to a resource or give me any assistance, I would appreciate it.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,236
14,999
Well, without knowing more about what you tried and why it didn't works, it will be difficult to help you.

I mean, here's the basic :
Code:
# Periods are : 0 night / 1 morning / 2 noon / 3 afternoon / 4 late
default period = 0
default maxPeriod = 5

label changePeriod:
   $ period += 1
   if period >= maxPeriod:
       $ period = 0
   return

label whatever:
    # If it's noon AND the event can happen
    if period == 2 and  eventGirls2 == 2:
        [do your event]
    else:
        [do the regular thing for this label]

    # Advance time
    call changePeriod
    jump whateverIsNext
And there's no reason for it to not works.

So, there's probably something that you haven't understood, or have misunderstood, in what you tried. And without knowing what it is, we can't explain it better to you.


Edit: Corrected a typo in the code.
 
Last edited:

CrimsonAxisStudio

Member
Game Developer
Nov 7, 2017
271
1,558
Well, without knowing more about what you tried and why it didn't works, it will be difficult to help you.

I mean, here's the basic :
Code:
# Periods are : 0 night / 1 morning / 2 noon / 3 afternoon / 4 late
default period = 0
default maxPeriod = 5

label changePeriod:
   $ period += 1
   if period >= maxPeriod:
       $ period = 0
   return

label whatever:
    # If it's noon AND the event can happen
    if period = 2 and  eventGirls2 == 2:
        [do your event]
    else:
        [do the regular thing for this label]

    # Advance time
    call changePeriod
    jump whateverIsNext
And there's no reason for it to not works.

So, there's probably something that you haven't understood, or have misunderstood, in what you tried. And without knowing what it is, we can't explain it better to you.
Thank you for the reply!

Just so that I know what's going on here, I will break some things down for myself just so someone can tell me if I'm right or wrong. Sorry, I'm new to coding, but I've been rendering for a long time.


Code:
# Periods are : 0 night / 1 morning / 2 noon / 3 afternoon / 4 late
default period = 0
default maxPeriod = 5
This block of code sets the default time and should go above label start because it is a variable? Not sure what this is called, just that that things that need to be tracked are to go before label start.

At the point that it gets to period "late" or 4, will it cycle back to 0 and create a loop of time?

Code:
label changePeriod:
   $ period += 1
   if period >= maxPeriod:
       $ period = 0
   return
This needs to be referenced by a call command after every label that would change time. Conversations, interactions, etc. This will advance the "clock".

Code:
label whatever:
    # If it's noon AND the event can happen
    if period = 2 and  eventGirls2 == 2:
        [do your event]
    else:
        [do the regular thing for this label]

    # Advance time
    call changePeriod
    jump whateverIsNext
The if period = 2 checks the current period according to the variable placed before label start, and eventGirls2 == 2 ... names the event to reference and execute?

Do you know of a resource that I can read to learn how to code events? Are events coded via python or renpy? For researching purposes.

Thanks again!
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,236
14,999
Code:
# Periods are : 0 night / 1 morning / 2 noon / 3 afternoon / 4 late
default period = 0
default maxPeriod = 5
This block of code sets the default time and should go above label start because it is a variable?
It create the variables, assign them their initial values and make them savable by default. And it can be wherever you want in the code ; but outside of a label and of an init block.


At the point that it gets to period "late" or 4, will it cycle back to 0 and create a loop of time?
Only if you ask it to do. It's just variables, they have the meaning and behavior you decide to give them with your code.


Code:
label changePeriod:
   $ period += 1
   if period >= maxPeriod:
       $ period = 0
   return
This needs to be referenced by a call command after every label that would change time. Conversations, interactions, etc. This will advance the "clock".
Yes.



Code:
label whatever:
    # If it's noon AND the event can happen
    if period = 2 and  eventGirls2 == 2:
        [do your event]
    else:
        [do the regular thing for this label]

    # Advance time
    call changePeriod
    jump whateverIsNext
The if period = 2 checks the current period according to the variable placed before label start, and eventGirls2 == 2 ... names the event to reference and execute?
Yes. More precisely, in this example I assumed that the events where tracked by stage. So, if it's the right period of time, and the event tracked by eventGirls2 is at its second stage, then the event will happen.


Do you know of a resource that I can read to learn how to code events?
Not really. There's too many way to do this for it to effectively have something like a how-to.
Basically speaking, you just need a variable to store the stage of the event, and test to see if a particular stage of a particular event can happen or not.
After, there's really tons of different way to implement this.


Are events coded via python or renpy? For researching purposes.
They can be coded in both, it depend how you want to do it.



Also, how does one go about changing the names of the periods?
Like I said, they are just variables. So, you just give them the meaning you want.

You should take a deeper look at Ren'py's documentation, that come with the SDK (in the "doc" folder), and at the two examples scripts that come with them. It would be a good start.