Ren'Py - Time Advance Issue

Xavster

Well-Known Member
Game Developer
Mar 27, 2018
1,243
7,551
Gotta love those coding drugs. o_O

I'm lmao, just need to learn the code to understand why. :LOL:
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,110
14,783
a return from the renpy.call() function? yes, unless you've used from_current=True as kwarg. then you would return to the call itself. :eek:
As far as I understood it, it's natural, and not scary at all. It's just that renpy.call, and especially this parameter, isn't designed to be used in inline Python, but only inside (CDS).

Internally, a call is just an exception thrown by Ren'py. Which mean that when you call a label, whatever with the call statement or renpy.call, Ren'py loose all memories about where it was at this moment. The only thing he remember is the entry point in the AST, or the next one, depending of what thrown the exception.
Therefore, you can't have a CDS that call a label, then either proceed the result, or react according to it.

By setting from_current to True, Ren'py will proceed the CDS two times. Firstly when it encounter the said CDS, then when he'll return from the called label. This permit your CDS to effectively proceed the new context and/or react to it. The only thing you need is a flag letting you know if it's the first processing of the statement (the one where you've to call), or the second (the one where you've to proceed the result).

The effective utility is limited, but this parameter isn't totally useless.
To stay more or less on context with the thread, you can have a bed_time CDS that ask the player how many time he want to sleep, then react accordingly to it.
It can be wrote without CDS :
Code:
    [...]
    call bed_time
    [...]

label bed_time:
    menu:
         "1 hour":
             call advance_time( 1 )
         "2 hours":
             call advance_time( 2 )
         "6 hours" if time > 20:
             call advance_time( 6 )
         "8 hours" if time > 20:
             call advance_time( 8 )
         "Until noon" if time > 22:
             call advance_time( (24-time) + 12 )
    return
or it can be wrote with a CDS :
Code:
    [...]
    bed_time
    [...]

menu bedTimeMenu:
         "1 hour":
             return( "nap" )
         "2 hours":
             return( "longNap" )
         "6 hours" if time > 20:
             return( "shortNight" )
         "8 hours" if time > 20:
             return( "longNight" )
         "Until noon" if time > 22 or time < 6:
             return(  "noon" )

init python:
    def bet_timeProcess( t ):
       if not _return in [ "nap", "longName", "shortNight", "longNight", "noon" ] :
           renpy.call( "bedTimeMenu", from_current=True )
       else:
           [proceed the time advance according to the result]
Obviously you can also use for this. But using the menu statement make the menu easier to write and update, offer you more flexibility, and let you benefit from the parameters, for both the menu and the choices.
This while the time advance processing while be proceeded directly in the function, instead of being a bunch of inline Python lines.
 

namiv

Member
Feb 19, 2020
135
62
another option, create your own screen action.

Python:
init python:
    class AdvanceTime(Action):
        def __call__(self):
            if renpy.store.dtime == 4:
                renpy.store.dtime = 0
                renpy.store.day += 1
            else:
                renpy.store.dtime += 1

            renpy.restart_interaction()

screen advance_time():
    zorder 200
    vbox xalign 0.9 yalign 0.05:
        imagebutton idle "advtime.png" action AdvanceTime()
If I want to have more than 4 parts in the day, dtime is the one i should chamge?
 

the66

beware, the germans are cumming
Modder
Respected User
Donor
Jan 27, 2017
7,594
23,529
If I want to have more than 4 parts in the day, dtime is the one i should chamge?
change the maximum value you compare dtime with, here the value 4.
 

RVNSN

Drunken Pirate Skirtchaser
Game Developer
Jan 17, 2019
738
436
Have been working on renders and corrections, so haven't implemented it yet, but if anyone needs to see a pretty clean example to handle it, check out the coding in Unforeseen Ascent.

The note I made for myself is:
- check park for time progression change - if there during day and you use time skip to night, the scene automatically changes


- look at: hud.rpy, time.rpy, park.rpy, gui.rpy

[edit: did this quite some time ago, but after getting advice on lemmasoft forums, I used ConditionSwitch to change the image(s) based on time of day, or for any other variable conditions]
 
Last edited:

LewdPie

Newbie
Jul 22, 2018
53
3
To reinforce what has been said before... but if you use call, there must be a corresponding return

jump is "Go THERE".
call is "Go THERE and then come back here".

... without the return the code has no clue about the "then come back here" part... which is the whole point of using call.

But to address your "advance time" code... I tend to focus on linear style games. So your open world approach (which I'm sure is fine) is a little alien to my way of thinking.

However, I wrote up this test script. The code works and I've tested it.
I don't know if it exactly fits what you're trying to do... but I've tried to do the whole generic "morning -> afternoon -> evening -> night" thing in a closed loop.

Maybe there's something here that can help you solve your own problem...

You don't have permission to view the spoiler content. Log in or register now.

The image I used is also attached... since it is the only thing stopping you cut and pasting this code into a temporary RenPy project on your own computer.

Edit: fixed the advance time button not being reshown when skipping forward to the middle of next day. It actually worked originally, but then I changed something else that broke it.
can someone please add hour to this script instead of morning, afternoon and evening, the day starts at 7 and ends at 24
 

RVNSN

Drunken Pirate Skirtchaser
Game Developer
Jan 17, 2019
738
436
can someone please add hour to this script instead of morning, afternoon and evening, the day starts at 7 and ends at 24
At a quick glance, I would say:

change -> define period_names = ["Morning", "Afternoon", "Evening", "Night"]
to something like -> define period_names = ["07:00", "08:00" ... "23:00", "00:00"]
... = fill in the rest of the hours, so there's one for each

default curr_period = "Morning"
to
default curr_period = "07:00"
 
  • Like
Reactions: 79flavors