[SOLVED] List of days cycles only through Sunday to Monday

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
tapanojum
Regular
Posts: 28
Joined: Tue Feb 27, 2018 4:33 am
Contact:

[SOLVED] List of days cycles only through Sunday to Monday

#1 Post by tapanojum »

Hi, I'm having issues getting my days to cycle.

Code: Select all

init:
    default days = 0

screen ui_text:
    if 0 <= float(minn/60)%24 < 1:
        $ days = days + 1
    $ day_num = (days % 7)
    $ day_name = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', ' Fri', 'Sat')
    $ day = day_name[day_num]
    zorder 101
    text "[day]"  size 36 color "#ffffff" font "IndieFlower-Regular.ttf" xpos 31 ypos 27
    text hour()  size 32 color "#ffffff" font "IndieFlower-Regular.ttf" xpos 110 ypos 32
So once the clock goes past midnight, days should continue from Sunday to Saturday. Instead what happens is that Sunday turns to Monday at midnight -1am, and then turns back to Sunday after 1am.

The culprit behind this is that the variable days never changes from anything but 0. Any ideas whats going on?
Last edited by tapanojum on Wed May 30, 2018 1:28 am, edited 1 time in total.

kivik
Miko-Class Veteran
Posts: 786
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: List of days cycles only through Sunday to Monday

#2 Post by kivik »

A couple of things wrong with your code:

1 - don't put default inside an init block. default goes outside any blocks.
2 - Don't put the logic inside your screen - screens should only display your data, you should have separate functions or classes to manage your data (your day and time).

With that in mind, either create a function that updates your days and day variable, or better yet, create a daytime class object to manage it. There should be some examples in the forum already but you seem to have the general idea of how to do it, so I'm sure you can work it out.

If you struggle with anything, post your updated code and we can give you more pointers :)

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: List of days cycles only through Sunday to Monday

#3 Post by xavimat »

Some explanations:

1. Is not actually wrong, is useless, because renpy knows that "default" will be executed at init phase.

2. The problem here is the prediction system. Renpy will predict what to show in a screen before it's actually showed to avoid glitches with complex screens. This prediction will happen an undetermined number of times. So, the screen should never contain side effects like changing global variables (your line $ days = days + 1 does that).
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

tapanojum
Regular
Posts: 28
Joined: Tue Feb 27, 2018 4:33 am
Contact:

Re: List of days cycles only through Sunday to Monday

#4 Post by tapanojum »

Thank you Kivik and Xavimat. I implemented your suggestions and the code is working correctly. For anyone curious for the solution:

Code: Select all

def which_day(day=0):

        global days
        day_num = (days % 7)
        day_name = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', ' Fri', 'Sat')
        day = day_name[day_num]
        return day
and then on the screen it calls the function.

Code: Select all

screen ui_text:
    zorder 101
    text which_day()  size 36 color "#ffffff" font "IndieFlower-Regular.ttf" xpos 31 ypos 27
    text hour()  size 32 color "#ffffff" font "IndieFlower-Regular.ttf" xpos 110 ypos 32
I am now having issues with the logic for keeping track of days. I have a 24 hour time system in place. Whenever it's passed midnight, I want the days to +1. I have two buttons that allows the players to pass time, either at 30m increment or 12 hours. My first draft of the code added a day whenever the clock struck midnight.

Code: Select all

if float(minn%1440) == 0:
            days = days + 1
            return days
However, if the player uses the +12 hours button, they can skip midnight all together and the day will not advance. Any ideas of how I can implement days to advance after a full 24h cycle?

Thank you again!

User avatar
xavimat
Eileen-Class Veteran
Posts: 1461
Joined: Sat Feb 25, 2012 8:45 pm
Completed: Yeshua, Jesus Life, Cops&Robbers
Projects: Fear&Love
Organization: Pilgrim Creations
Github: xavi-mat
itch: pilgrimcreations
Location: Spain
Discord: xavimat
Contact:

Re: List of days cycles only through Sunday to Monday

#5 Post by xavimat »

I always use a while loop for time passing. I use a function too:

Code: Select all

default minute = 0
default hour = 0
default day = 0
init python:
    def tempus_fugit(m, h=0, d=0):
        global minute, hour, day
        minute += m
        hour += h
        day += d
        while minute > 59:
            hour += 1
            minute -= 60
        while hour > 23:
            day += 1
            hour -= 24
Comunidad Ren'Py en español: ¡Únete a nuestro Discord!
Rhaier Kingdom A Ren'Py Multiplayer Adventure Visual Novel.
Cops&Robbers A two-player experiment | Fear&Love Why can't we say I love you?
Honest Critique (Avatar made with Chibi Maker by ~gen8)

tapanojum
Regular
Posts: 28
Joined: Tue Feb 27, 2018 4:33 am
Contact:

Re: List of days cycles only through Sunday to Monday

#6 Post by tapanojum »

Xavimat, thank you for your reply. That is such a simple and perfect solution. I have no idea why I couldn't think of it. I kept messing with modulo when this works so much better.

Thanks again!

Post Reply

Who is online

Users browsing this forum: decocloud