Renpy question - monday to friday, day and night system.

Andurin

Member
Apr 28, 2017
380
2,940
Hello dear F95ZONE peps.

I am trying to make my own renpy game, where you play a protaganist, who has to work to make rent so her boyfriend and keep studying and their landlord does throws them out (Unoriginal plot, but first time game).

I need some how to implant a week system, so you can go to difference places and do stuff. then progress to night, before you progress to the next day. Also it would be very nice if the there was a week system, like monday to sunday.

Kinda like the ui platform you see in games like Akabur's Princess trainer.

I dont mind learning how to do it on my own, but i right now am i hitting a wall looking for the "programming terms" for the stuff i want to implant :D

Best regards
 

Paitryn

Well-Known Member
Mar 10, 2017
1,505
2,049


I use this when messing around in ren'py. There are tons of resources on those forums
 

polywog

Forum Fanatic
May 19, 2017
4,063
6,258
Is there a renpy game out there that you know of that has a similar schedule to what you want to do?
If you didn't study for the test, you might peek over their shoulder and see how they did it. To help you figure out how you can do it.
 

Andurin

Member
Apr 28, 2017
380
2,940
I appricate the inputs :)

I have look at a few games, what i was searching for was the name of the "system" used :)

Again thanks and i will get on with my project.
 

shiza

Newbie
Mar 6, 2017
27
37
the best way to implement it that I found is through variable manipulation. so have variable called "days" and "time_of_day". days can range from 1-7 so each value is a day 1= Mon, 2= Tues, etc. The time of day you can make as complex or as simple as you want. i prefer doing the same thing I did with days except 1= morning, 2= afternoon, 3 = dusk, 4 = night.

now the hard part is making sure you don't go past the bounds of this variable limits. do this by routinely checking if days >=8 or time_of_days >= 5. if they do send an error message by posting the location of the code so that you can better manage your time tracking.
 

Derover

Member
Modder
Nov 11, 2016
158
267
the best way to implement it that I found is through variable manipulation. so have variable called "days" and "time_of_day". days can range from 1-7 so each value is a day 1= Mon, 2= Tues, etc. The time of day you can make as complex or as simple as you want. i prefer doing the same thing I did with days except 1= morning, 2= afternoon, 3 = dusk, 4 = night.

now the hard part is making sure you don't go past the bounds of this variable limits. do this by routinely checking if days >=8 or time_of_days >= 5. if they do send an error message by posting the location of the code so that you can better manage your time tracking.
Instead of the check, can't you do something like this:

public gotoNextDay() {
//do everyday updates here
updateStats()
//increment day
day++;
day = day%7;
}

Where day = 0 is monday and day = 6 is sunday. It's not that that difficult to keep between bounds.
And you could make it so that you have two variables day and weekDay, so you do weekDay = day%7 and you keep incrementing day. This way you can keep track of the total amount of days at the same time.
This is ofcourse just some pseudocode, just to explain the idea.
 

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,648
28,390
Yeah, Vren's implementation in Lab Rats works pretty well. I think I improved upon it a bit back in the 0.3.0 days, let me check while waiting on a download...

Yep, I cleaned up the 0.3.0 version a bit (days were in a bunch of if statements before). Here's the code:
Code:
    $ day_number = (day%7)
    $ day_name_values = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
    $ day_name = day_name_values[day_number]
If you want Day 1 to start on a day other than Sunday, simply rearrange the day of week variables appropriately (i.e. start with Wednesday if you want Wednesday to be Day 1). Also, you may want to start with Day 1 with this in your game. I haven't tested this with a Day 0 yet...
 
Last edited:

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,648
28,390
I noticed after I made my last post that I didn't address the other part of your question, i.e. morning, night, etc..

Here's what I did:

Code:
    $ time_name_values = ("Morning", "Afternoon", "Evening", "Night", "Dawn")
    $ time_name = time_name_values[dayTime]
    $ time = 6 + (time_increment * 2) + (dayTime * 6)
    $ time2 = time
    if time2 > 23:
        $ time2 -= 24
    $ ampm = "am"
    if 24 > time2 > 11:
        $ time2 -= 12
        $ ampm = "pm"
    if time2 == 0:
        $ time2 = 12
The time_increment thing was something I was trying, to break down the four main periods into 2 hour increments. Some actions wouldn't take up the entire 6 hours. There were some code checks for this that I added in the other areas of the code which tracked this.

Dawn was an additional 'time separator' that I introduced to handle the 'daily chores' with the variables before proceeding to morning stuff.

Anyways, even if you are good with just the time_name_values without the time_increment thing, this code might still be of use for you (just delete what you don't need). Or if you like the time increment thing, put it to use!

As for how to use all of this in a date display, here's how I had it set up in my (unreleased and now very outdated) LR mod...

Code:
    text "{size=32}Day [day]{/size} - [day_name] [time_name]" color "#4CC" outlines [ (2, "#000", 0, 0) ] size 26 bold True pos (5, 1038)
    text "[time2][ampm]" color "#AAA" size 30 outlines [ (2, "#000", 0, 0) ] text_align 1.0 line_spacing 0 bold True xpos 5 ypos 1003
I broke these up into two lines, to differentiate them by color. you could easily combine the two lines if you weren't worried about such things.

Anyways, I hope that you find all of this useful...
;)
 

Zenathos815

Newbie
Jul 26, 2017
53
23
I noticed after I made my last post that I didn't address the other part of your question, i.e. morning, night, etc..

Here's what I did:

Code:
    $ time_name_values = ("Morning", "Afternoon", "Evening", "Night", "Dawn")
    $ time_name = time_name_values[dayTime]
    $ time = 6 + (time_increment * 2) + (dayTime * 6)
    $ time2 = time
    if time2 > 23:
        $ time2 -= 24
    $ ampm = "am"
    if 24 > time2 > 11:
        $ time2 -= 12
        $ ampm = "pm"
    if time2 == 0:
        $ time2 = 12
The time_increment thing was something I was trying, to break down the four main periods into 2 hour increments. Some actions wouldn't take up the entire 6 hours. There were some code checks for this that I added in the other areas of the code which tracked this.

Dawn was an additional 'time separator' that I introduced to handle the 'daily chores' with the variables before proceeding to morning stuff.

Anyways, even if you are good with just the time_name_values without the time_increment thing, this code might still be of use for you (just delete what you don't need). Or if you like the time increment thing, put it to use!

As for how to use all of this in a date display, here's how I had it set up in my (unreleased and now very outdated) LR mod...

Code:
    text "{size=32}Day [day]{/size} - [day_name] [time_name]" color "#4CC" outlines [ (2, "#000", 0, 0) ] size 26 bold True pos (5, 1038)
    text "[time2][ampm]" color "#AAA" size 30 outlines [ (2, "#000", 0, 0) ] text_align 1.0 line_spacing 0 bold True xpos 5 ypos 1003
I broke these up into two lines, to differentiate them by color. you could easily combine the two lines if you weren't worried about such things.

Anyways, I hope that you find all of this useful...
;)
I browsed this just in time. I was royally fucking up my own day system. I may have fooled myself before taking on my current project just as much as py tom fooled me lol. Maybe it's because my code experience is in java (not the fun kind) bootstrap SOME php and I was pretty rad at python back like 6 years ago. I'm pretty good at interpreting code and once I get a concept I tend to get really good at it. Ren'py fooled me. I was pretty comfortable navigating scripts and making my mods such as adding characters and locations but I didn't expect that starting from scratch would be so daunting. Definitely not the kinda language I am accustomed to writing...

Any who, would you hate me if I used this and reworked it a bit? I would appreciate you dearly
 

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,648
28,390
I browsed this just in time. I was royally fucking up my own day system. I may have fooled myself before taking on my current project just as much as py tom fooled me lol. Maybe it's because my code experience is in java (not the fun kind) bootstrap SOME php and I was pretty rad at python back like 6 years ago. I'm pretty good at interpreting code and once I get a concept I tend to get really good at it. Ren'py fooled me. I was pretty comfortable navigating scripts and making my mods such as adding characters and locations but I didn't expect that starting from scratch would be so daunting. Definitely not the kinda language I am accustomed to writing...

Any who, would you hate me if I used this and reworked it a bit? I would appreciate you dearly
It's just an example, so do whatever you like!
 
  • Like
Reactions: Zenathos815

Master1995

Newbie
Sep 20, 2017
23
45
If someone else (with beginner skills) needs simple code for week, day time, money system that is shown on screen, here it is! :D

You need to paste this code on the bottom of screens.rpy:
Code:
screen money_display:

    $ day_number = (day%7)
    $ day_name_values = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
    $ dayn = day_name_values[day_number]

    $ dtime_number = (dtime%6)
    $ dtime_name_values = ("Early morning", "Morning", "Noon", "Afternoon", "Night", "Late night")
    $ dtimen = dtime_name_values[dtime_number]

    vbox:
        xalign .01 #change this value between 0 and 1 if you want to move it to a different part of the screen horizontally
        yalign .01 #change this value if you want to move it to a different part of the screen vertically

        text "Money=[money] Day=[day] [dayn] [dtimen]" #this will show your money points variable, you can add extra parameters such as font type, size, alignment etc
When you want to show or hide "Money=[money] Day=[day] [dayn] [dtimen]" on your screen, use this commands in script.rpy:
Code:
show screen money_display

OR

hide screen money_display
Also, on top of you script.rpy you need to define used variables like this example:
Code:
default money = 100 #set starting money value
default day = 0 #set starting day of the week (0 is Sunday, 1 is Monday, ..., 6 is Saturday)
default dtime = 0 #set starting part of the day (0 is early morning, 1 is morning, ..., 5 is late night)
Image of shown example: Rpy.png
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,094
14,736
If someone else (with beginner skills) needs simple code for week, day time, money system that is shown on screen, here it is! :D
What I dislike with this screen is that it pollute unnecessarily the store. All values are local to the screen, they don't need to leak outside of it. So, use the screen statement to declare them local to the screen, and use anonymous lists to compute the wanted values :

Python:
screen money_display:

    default dName = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][day%7]
    default tName = [ "Early morning", "Morning", "Noon", "Afternoon", "Night", "Late night" ][dtime%6]

    vbox:
        xalign .01
        yalign .01
        text "Money=[money] Day=[day] [dName] [tName]"
 

Master1995

Newbie
Sep 20, 2017
23
45
What I dislike with this screen is that it pollute unnecessarily the store. All values are local to the screen, they don't need to leak outside of it. So, use the screen statement to declare them local to the screen, and use anonymous lists to compute the wanted values :

Python:
screen money_display:

    default dName = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][day%7]
    default tName = [ "Early morning", "Morning", "Noon", "Afternoon", "Night", "Late night" ][dtime%6]

    vbox:
        xalign .01
        yalign .01
        text "Money=[money] Day=[day] [dName] [tName]"
adding 1 to day or dtime in script.rpy, doesn't affect dName or tName for me on that example... but if I put "$" instead of "default" it flows like a baby...
 

Kinderfeld

Developer of Now & Then and The Interim Domain
Game Developer
Feb 11, 2018
405
3,213
If someone else (with beginner skills) needs simple code for week, day time, money system that is shown on screen, here it is! :D

You need to paste this code on the bottom of screens.rpy:
Code:
screen money_display:

    $ day_number = (day%7)
    $ day_name_values = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
    $ dayn = day_name_values[day_number]

    $ dtime_number = (dtime%6)
    $ dtime_name_values = ("Early morning", "Morning", "Noon", "Afternoon", "Night", "Late night")
    $ dtimen = dtime_name_values[dtime_number]

    vbox:
        xalign .01 #change this value between 0 and 1 if you want to move it to a different part of the screen horizontally
        yalign .01 #change this value if you want to move it to a different part of the screen vertically

        text "Money=[money] Day=[day] [dayn] [dtimen]" #this will show your money points variable, you can add extra parameters such as font type, size, alignment etc
When you want to show or hide "Money=[money] Day=[day] [dayn] [dtimen]" on your screen, use this commands in script.rpy:
Code:
show screen money_display

OR

hide screen money_display
Also, on top of you script.rpy you need to define used variables like this example:
Code:
default money = 100 #set starting money value
default day = 0 #set starting day of the week (0 is Sunday, 1 is Monday, ..., 6 is Saturday)
default dtime = 0 #set starting part of the day (0 is early morning, 1 is morning, ..., 5 is late night)
Image of shown example: View attachment 247828
I know I'm probably necroing the hell out of this post, but I gotta say this worked perfectly for me. Working on the game engine for another project and I only needed Day # and Day of the Week and this worked like a charm. Even let me set up code to pull Saturday and Sunday events.

Code:
label homescenes:
    if day == 1:
        jump home1
    if day == 2:
        jump home2
#
#[put in a bunch of shit here for the rest of the week]
#
    if (day%7 == 6):
        jump sathome
    if (day%7 == 6):
        jump sunhome
 
  • Red Heart
Reactions: Master1995

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,094
14,736
Code:
label homescenes:
    if day == 1:
        jump home1
    if day == 2:
        jump home2
#
#[put in a bunch of shit here for the rest of the week]
#
    if (day%7 == 6):
        jump sathome
    if (day%7 == 6):
        jump sunhome
It would be better if you used elif, as well as else :
Code:
    if day == 1:
        jump home1
    elif day == 2:
        jump home2
    [...]
    else:
        $ renpy.notify( "Oops, something goes wrong" )
        jump SOME_DEFAULT_LABEL
The use of continuous if in place of the if/elif/else structure is one of the most common reason behind subtle bugs, which break the game mechanism without crashing the game.
And even the most basic conditions can lead to errors without an else, because a typo can always happen.

Take what you wrote by example :
Code:
    if (day%7 == 6):
        jump sathome
    if (day%7 == 6):
        jump sunhome
as it is wrote, there's supposedly no condition for day%7 == 5 or for day%7 == 0 ; depending if it's the condition for Saturday or for Sunday that have the typo.
Therefore, as it is, when the game will reach Saturday (or Sunday), Ren'py will find no jump, and simply continue with what come right after your "homescenes" label.

You would be able to see it when testing your game, because you know that there's a Saturday scene and what is this scene. But the player don't know it, and will just assume that what happen is normal ; therefore, you'll never have a bug report for this error.
But, with the use of else, especially as catch all like I wrote it here, the players will be warned that there's something wrong, and at least one will report it to you.
 
  • Like
Reactions: Cul and Kinderfeld

Kinderfeld

Developer of Now & Then and The Interim Domain
Game Developer
Feb 11, 2018
405
3,213
It would be better if you used elif, as well as else :
Code:
    if day == 1:
        jump home1
    elif day == 2:
        jump home2
    [...]
    else:
        $ renpy.notify( "Oops, something goes wrong" )
        jump SOME_DEFAULT_LABEL
The use of continuous if in place of the if/elif/else structure is one of the most common reason behind subtle bugs, which break the game mechanism without crashing the game.
And even the most basic conditions can lead to errors without an else, because a typo can always happen.

Take what you wrote by example :
Code:
    if (day%7 == 6):
        jump sathome
    if (day%7 == 6):
        jump sunhome
as it is wrote, there's supposedly no condition for day%7 == 5 or for day%7 == 0 ; depending if it's the condition for Saturday or for Sunday that have the typo.
Therefore, as it is, when the game will reach Saturday (or Sunday), Ren'py will find no jump, and simply continue with what come right after your "homescenes" label.

You would be able to see it when testing your game, because you know that there's a Saturday scene and what is this scene. But the player don't know it, and will just assume that what happen is normal ; therefore, you'll never have a bug report for this error.
But, with the use of else, especially as catch all like I wrote it here, the players will be warned that there's something wrong, and at least one will report it to you.
Thanks for the feedback and information. Will do this going forward.
 

xxx3me

Newbie
Jun 19, 2020
57
29
Just to confirm: only way to change week day/period name was using $ instead of default, as pointed by Master1995.

So:
Python:
$ dName = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][day%7]
$ tName = ["Morning", "Afternoon", "Night", "Late night"][dtime%4]
Did the trick. No idea why :D, but working this way.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,094
14,736
Just to confirm: only way to change week day/period name was using $ instead of default, as pointed by Master1995.
Which is totally normal since $ is to introduce an inline python code that will be proceeded when the game will hit the line, while default is to assign a value to a variable when the game will start.

In addition to be incorrect, things like this :
Code:
label start:
    "myVar value is [myVar]"
    $ myVar = "something totally different"
    jump whatever

label whatever:
    default myVar = "some value"
    "myVar value is [myVar]"
    "End"
    return
will not change the behavior of default. The variable "myVar" will be created and assigned its value right after the player hit the "start" button, not when the game will finally reach the "whatever" label.
 
Jul 14, 2018
417
1,602
Which is totally normal since $ is to introduce an inline python code that will be proceeded when the game will hit the line, while default is to assign a value to a variable when the game will start.
Thanks for that. A lot of weird things are suddenly making a lot of sense.