Time progression help

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
wal888
Newbie
Posts: 4
Joined: Sat Feb 20, 2021 7:19 pm
Contact:

Time progression help

#1 Post by wal888 »

Hello! I am a beginner Renpy coder so sorry for any errors! I've been trying to keep the coding simple for now until I learn more.
I am trying to have an object (a bed) increase time in the game. I have the bed as an imagebutton:

screen bed_westbedroom2():
imagebutton:
action Call("WestBedroom2BedMenu")

and clicking on it calls this label:

label WestBedroom2BedMenu:

menu:
"Nap":
call Nap

"Sleep Until Next Day":
call Sleep

"Back":
return

$ renpy.pause(hard=True)

label Nap:

$Time += 1
return

label Sleep:

$Day += 1
$Time = 0
return

And have this as the variables:

$ WeekDays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
$ TimeofDay = ["Morning", "Noon", "Afternoon", "Evening", "Night", "Midnight"]
$ Day = 0
$ Time = 4
$ Output = WeekDays[Day] + " " + TimeofDay[Time]
if Time > 5:
$ Time = 0
$ Day += 1
if Day > 6:
$ Day = 0

I can't get the time to progress (I have the Output variable showing on the screen as a hud). Any help would be appreciated, thanks!

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Time progression help

#2 Post by zmook »

Where is Output defined? If it's not in the screen, or if the screen doesn't call some kind of update_time function, then it may be getting set once and never updated.

If you have set config.developer = True, hit shift-D and then choose the Variable Viewer. You can see if Day and Time are getting updated like you expect.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

wal888
Newbie
Posts: 4
Joined: Sat Feb 20, 2021 7:19 pm
Contact:

Re: Time progression help

#3 Post by wal888 »

Thanks for the reply zmook! Yeah, I was thinking that the hud might not be updating the variables every time. I'm not sure how to create an update time function. Right now I have the screens like this:

screen hud():
imagebutton:
xalign 1.0
yalign 0.0
idle "hud.png"

screen hudtime():
textbutton "[Output]":
xalign 0.87
yalign 0.01

screen moneyamount():
textbutton "$ [Money]":
xalign 0.96
yalign 0.01

And in the labels I have this:

show screen hud
call variables
show screen hudtime
show screen moneyamount

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: Time progression help

#4 Post by zmook »

I think you want something like this. (This uses a 24h clock, but I'll leave it up to you to swap "hours" for your periods "morning", "afternoon", etc.)

Code: Select all

define time.days = (_("Sunday"), _("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), 
                      _("Friday"), _("Saturday"))

init python in time:

    day = hour = week = day_of_week = 0
    day_name = "undef"

    def update_time(clock):
        global days, day, hour, week, day_of_week, day_name
        day = int(clock / 24) + 1
        hour = int(clock % 24)
        week = int(day / 7) + 1
        day_of_week = int(day % 7)
        day_name = days[day_of_week]

Code: Select all

screen status_overlay:
    $ time.update_time(clock)
    
    frame:
        background "#fda"
        has vbox:
            text "Week [time.week], [time.day_name], [time.hour]h00"
            text "Money: $[money]"

And then you advance time with code like this:

Code: Select all

default clock = 11      # hours since midnight on Day 1

label sleep: 

    "You sleep, perchance to dream."
    $ clock += 7
    $ awake_since = clock
    
    return
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

wal888
Newbie
Posts: 4
Joined: Sat Feb 20, 2021 7:19 pm
Contact:

Re: Time progression help

#5 Post by wal888 »

Awesome, thanks zmook! After some fiddling around I got it to work. Many thanks!

Post Reply

Who is online

Users browsing this forum: No registered users