Ren'Py My time code is not working properly

Apr 4, 2022
22
5
CODE:



default day = 1
default time_stamp= 0
default time_of_day = "Early Morning"
default day_name = "Sunday"
init:
$ day_image = "images/sonntag.png"
$ time_image = "images/fmorgen.png"
screen time_display:
if time_stamp <10 :
$ time_of_day = "Early_Morning"

elif time_stamp >=10 and time_stamp <20 :
$ time_of_day = "Morning"
$ time_image ="images/morgen.png"
elif time_stamp >= 20 and time_stamp <30 :
$ time_of_day = "Noon"
$ time_image = "images/mittags.png"
elif time_stamp >= 30 and time_stamp <40 :
$ time_of_day = "After_Noon"
$ time_image = "images/mittags.png"
elif time_stamp >= 40 and time_stamp <50 :
$ time_of_day = "Evening"
$ time_image = "images/abends.png"
elif time_stamp >= 50 and time_stamp <60 :
$time_of_day = "Night"
$ time_image = "images/nachts.png"
elif time_stamp >= 60:
$ day += 1
$ time_stamp = 0
if day == 1:
$day_name = "Sunday"
$ day_image = "images/sonntag.png"
elif day == 2:
$day_name = "Monday"
$ day_image = "images/montag.png"
elif day == 3:
$day_name = "Tuesday"
$ day_image = "images/dienstag.png"
elif day == 4:
$day_name = "Wednesday"
$ day_image = "images/mittwoch.png"
elif day == 5:
$day_name = "Thursday"
$ day_image = "images/donnerstag.png"
elif day == 6:
$day_name = "Friday"
$ day_image = "images/Freitag.png"
elif day == 7:
$day_name = "Saturday"
$ day_image = "images/samstag.png"
elif day == 8:
$day = 1
The above is my code for changing period of a day and weekdays. It works fine when starting from Sunday but it gets stuck on Monday Early morning and doesn't move forward in time. How can I fix this issue/
 
Last edited:

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
Sadly, indentation matters here.

So to make it easier for myself and other to diagnose...

Python:
default day = 1
default time_stamp= 0
default time_of_day = "Early Morning"
default day_name = "Sunday"

init:
    $ day_image = "images/sonntag.png"
    $ time_image = "images/fmorgen.png"

screen time_display:

    if time_stamp < 10 :
        $ time_of_day = "Early_Morning"

    elif time_stamp >= 10 and time_stamp < 20 :
        $ time_of_day = "Morning"
        $ time_image ="images/morgen.png"

    elif time_stamp >= 20 and time_stamp < 30 :
        $ time_of_day = "Noon"
        $ time_image = "images/mittags.png"

    elif time_stamp >= 30 and time_stamp < 40 :
        $ time_of_day = "After_Noon"
        $ time_image = "images/mittags.png"

    elif time_stamp >= 40 and time_stamp < 50 :
        $ time_of_day = "Evening"
        $ time_image = "images/abends.png"

    elif time_stamp >= 50 and time_stamp < 60 :
        $ time_of_day = "Night"
        $ time_image = "images/nachts.png"

    elif time_stamp >= 60:
        $ day += 1
        $ time_stamp = 0

    if day == 1:
        $ day_name = "Sunday"
        $ day_image = "images/sonntag.png"

    elif day == 2:
        $ day_name = "Monday"
        $ day_image = "images/montag.png"

    elif day == 3:
        $ day_name = "Tuesday"
        $ day_image = "images/dienstag.png"

    elif day == 4:
        $ day_name = "Wednesday"
        $ day_image = "images/mittwoch.png"

    elif day == 5:
        $ day_name = "Thursday"
        $ day_image = "images/donnerstag.png"

    elif day == 6:
        $ day_name = "Friday"
        $ day_image = "images/Freitag.png"

    elif day == 7:
        $ day_name = "Saturday"
        $ day_image = "images/samstag.png"

    elif day == 8:
        $day = 1

Hopefully I'll get chance to look at this further later today.

But a couple of quick observations.

All this is taking place within a screen... that may be playing a part, especially if the screen is mistaking some of those variables for local screen variables rather than ones stored in the store (global variables).

Python:
init:
    $ day_image = "images/sonntag.png"
    $ time_image = "images/fmorgen.png"

Should probably be:

Python:
default day_image = "images/sonntag.png"
default time_image = "images/fmorgen.png"

Since they are just normal variables like all the others. init: blocks are rarely the correct solution these days for initializing variables.

Python:
    if time_stamp <10 :
        $ time_of_day = "Early_Morning"

Should probably be:
(you forgot to set the image)

Python:
    if time_stamp <10 :
        $ time_of_day = "Early_Morning"
        $ time_image = "images/fmorgen.png"

Only the local -vs- global variables come to mind as being the actual solution to your original problem. Though I haven't had chance to investigate it properly.

Finally... I would move that check for if day == 8 to before the checks for if day == 1.
If the day has wrapped around, you want it to move to from Saturday to Sunday before you assign names. Like:

Python:
    if day == 8:
        $day = 1

    if day == 1:
        $ day_name = "Sunday"
        $ day_image = "images/sonntag.png"

    elif day == 2:
        $ day_name = "Monday"
        $ day_image = "images/montag.png"

    # etc.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,192
All this is taking place within a screen... that may be playing a part, especially if the screen is mistaking some of those variables for local screen variables rather than ones stored in the store (global variables).
The code being in the screen totally is the reason. But not because of a conflict between local and global variables.

Look at the code, the time and day advance, at the end of the loop and the loop isn't proceeded again after this.
Therefore, the time/day advance, but the game have no time of the day value, nor would it have day value, to show the player.


Finally... I would move that check for if day == 8 to before the checks for if day == 1.
It solve the issue, yes. But it's a dirty fix because the day changing part (therefore if time_stamp >= 60 and if day == 8) should be part of the time advance code, not of the time display one.

Python:
label advanceTime( step ):
    $ time_stamp += step
    while time_stamp >= 60:
        $ time_stamp -= 60
        $ day += 1
    # since he starts a 1 and not at 0 a modulo wouldn't do it
    while day >= 8:
        $ day -= 7

    return

label whatever:
    [...]
    "I'm glad we goes to see this movie together"
    call advanceTime( 20 )

Since I'm at it, the day part can easily be simplified:
Python:
# Again, he starts a 1
define dayNames = [ None, "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
define dayImages = [ None, "images/sonntag.png", "images/montag.png", "images/dienstag.png", "images/mittwoch.png", "images/donnerstag.png", "images/Freitag.png", "images/samstag.png" ]

screen time_display():

    if time_stamp < 10 :
        [...]

    $ day_name = dayNames[day]
    $ day_image = dayImages[day]
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,607
2,256
It solve the issue, yes. But it's a dirty fix because...
[/code]

Oh, don't get me wrong. If I find some time today, I'd be writing a complete replacement example.
But that was just how much time I could spare earlier today. :)

Though given you've pretty much coded everything I had in my head within your reply... I don't need to. Win/Win. :)
The only other thing I would want to add would be a modulus calculation for wrapping around the times and days.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,957
16,192
The only other thing I would want to add would be a modulus calculation for wrapping around the times and days.
I leave it to you with pleasure.

And it's absolutely not because his use of tenth make it a bit too difficult for my brain at its current level of frying :whistle:
 
  • Like
Reactions: 79flavors
Apr 4, 2022
22
5
Sadly, indentation matters here.

So to make it easier for myself and other to diagnose...

Python:
default day = 1
default time_stamp= 0
default time_of_day = "Early Morning"
default day_name = "Sunday"

init:
    $ day_image = "images/sonntag.png"
    $ time_image = "images/fmorgen.png"

screen time_display:

    if time_stamp < 10 :
        $ time_of_day = "Early_Morning"

    elif time_stamp >= 10 and time_stamp < 20 :
        $ time_of_day = "Morning"
        $ time_image ="images/morgen.png"

    elif time_stamp >= 20 and time_stamp < 30 :
        $ time_of_day = "Noon"
        $ time_image = "images/mittags.png"

    elif time_stamp >= 30 and time_stamp < 40 :
        $ time_of_day = "After_Noon"
        $ time_image = "images/mittags.png"

    elif time_stamp >= 40 and time_stamp < 50 :
        $ time_of_day = "Evening"
        $ time_image = "images/abends.png"

    elif time_stamp >= 50 and time_stamp < 60 :
        $ time_of_day = "Night"
        $ time_image = "images/nachts.png"

    elif time_stamp >= 60:
        $ day += 1
        $ time_stamp = 0

    if day == 1:
        $ day_name = "Sunday"
        $ day_image = "images/sonntag.png"

    elif day == 2:
        $ day_name = "Monday"
        $ day_image = "images/montag.png"

    elif day == 3:
        $ day_name = "Tuesday"
        $ day_image = "images/dienstag.png"

    elif day == 4:
        $ day_name = "Wednesday"
        $ day_image = "images/mittwoch.png"

    elif day == 5:
        $ day_name = "Thursday"
        $ day_image = "images/donnerstag.png"

    elif day == 6:
        $ day_name = "Friday"
        $ day_image = "images/Freitag.png"

    elif day == 7:
        $ day_name = "Saturday"
        $ day_image = "images/samstag.png"

    elif day == 8:
        $day = 1

Hopefully I'll get chance to look at this further later today.

But a couple of quick observations.

All this is taking place within a screen... that may be playing a part, especially if the screen is mistaking some of those variables for local screen variables rather than ones stored in the store (global variables).

Python:
init:
    $ day_image = "images/sonntag.png"
    $ time_image = "images/fmorgen.png"

Should probably be:

Python:
default day_image = "images/sonntag.png"
default time_image = "images/fmorgen.png"

Since they are just normal variables like all the others. init: blocks are rarely the correct solution these days for initializing variables.

Python:
    if time_stamp <10 :
        $ time_of_day = "Early_Morning"

Should probably be:
(you forgot to set the image)

Python:
    if time_stamp <10 :
        $ time_of_day = "Early_Morning"
        $ time_image = "images/fmorgen.png"

Only the local -vs- global variables come to mind as being the actual solution to your original problem. Though I haven't had chance to investigate it properly.

Finally... I would move that check for if day == 8 to before the checks for if day == 1.
If the day has wrapped around, you want it to move to from Saturday to Sunday before you assign names. Like:

Python:
    if day == 8:
        $day = 1

    if day == 1:
        $ day_name = "Sunday"
        $ day_image = "images/sonntag.png"

    elif day == 2:
        $ day_name = "Monday"
        $ day_image = "images/montag.png"

    # etc.
Thanks for the advice. But sadly it doesn't work. I think I have to use list or class for it.
 
Apr 4, 2022
22
5
Python:
label advanceTime( step ):
    $ time_stamp += step
    while time_stamp >= 60:
        $ time_stamp -= 60
        $ day += 1
    # since he starts a 1 and not at 0 a modulo wouldn't do it
    while day >= 8:
        $ day -= 7

    return

label whatever:
    [...]
    "I'm glad we goes to see this movie together"
    call advanceTime( 20 )
[/QUOTE]
Thank you very much. This worked.