renpy day time....

Cohibozz

Member
Aug 14, 2018
125
27
i'm new in renpy and trying to do my daytime screen. It works fine but i don't know ho to update the screen properly if i click on it.

if i click on my work the time go ahead by 1 hour but the period don't change properly and the function for set > 23 = 00 don't trigger.

i post my codes.
Code:
screen daytime:
    hbox:
        xalign 0.0 yalign 0.0
        textbutton "[todays]"

        textbutton "[time]:00 - [nowfase]":
            action SetVariable("time", time + 1)
                RestartStatement()
and in script.pry

Code:
init:
 $ day = 0
 $ todays = "Tue"
 $ daynames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
 $ todays =  daynames[(day%7)]
 $ time = 12
 if time > 23:
     $time = 00
     $day += 1
 $ fasetime = ["Late Night", "Morning", "Afternoon", "Evening", "Night"]
 $ nowtime = (time + 1)
 $ nowfase = fasetime[(nowtime / 6)]
pls help me...
 

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,662
28,506
OK, this looks a bit like something I posted before that I used in a personal Lab Rats mod.

A couple of things that jump out at me.

$day is supposed to be numeric, but 00 is a 'display' convention, not a true numeric value. Not sure if this is causing issues, but try 0 instead of 00...

You have five time periods, but your divisor (6) is set up for four time periods. I did the same, but I need to check if Dawn (what you call Late Night) actually showed up. Also, I had Dawn at the end of the string list, not the beginning.

Looking over my code, Dawn (Late Night for you) would only show up if dayTime (fasetime for you) was 'manually' assigned as 4. I used this (forcing the '4') after the conclusion of sleepless night events, with a 'you didn't get any sleep last night' message before resetting to 0.

Also, I had the time checks assigned to a screen, not init. In Lab Rats at least, things assigned to screen were calculated in 'real time' based on current values. I had a number of other stat checks that I did under screens as well. Either way, after sleeping or a sleeples night, I would jump to a 'NewDay' label where dayTime was reset to 0.

Others may have more insightful thoughts on this.
 

Cohibozz

Member
Aug 14, 2018
125
27
You have five time periods, but your divisor (6) is set up for four time periods. I did the same, but I need to check if Dawn (what you call Late Night) actually showed up. Also, I had Dawn at the end of the string list, not the beginning.
i've divided my day for 6 : 24/6 = 4 hour for 6 period.

the :
$ nowtime = (time + 1)
is for force period to occur 1 hour first (5 insted 6 for moning, 11 insted 12 for evening...) for force the day in 5 period. and it's work better.

the base code i've taken for your post (thanks )

now i try to make the change u say to do.. ù(sorry for my english , i'm italian ::)
 

Cohibozz

Member
Aug 14, 2018
125
27
i've changed as u say me for variables and now it's ok.

Code:
screen daytime:
    if hour > 23:
        $hour = 0
        $day += 1
    $ todays = "Tue"
    $ daynames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    $ todays =  daynames[(day%7)]

    $ fasetime = ["Late Night", "Morning", "Afternoon", "Evening", "Night"]
    $ nowtime = (hour + 2)
    $ nowfase = fasetime[(nowtime / 6)]
    hbox:
        xalign 0.0 yalign 0.0
        textbutton "[todays]"

        textbutton "[hour]:00 - [nowfase]":
            action SetVariable("hour", hour + 1)
                RestartStatement()

i've changed hour+1 in hour+2 for better period ...but i've 1 problem now...

when the day change at 0:00 the screen stop working...not action on click
why this? i've to put some in if statement?
 

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,662
28,506
Not sure what the RestartStatement() is for, but it may not be necessary. I've never seen that used, so others will understand what it's for.

Also, the $ todays = "Tue" probably should be under the initial (init) variable declarations, as you are defining todays twice in the screen. I'm guessing you want the game to start on a Tuesday. Another way to go about that would be to 'reorder' the day names in the string (i.e. start with Mon or Tue in the string instead of Sun), so that on Day 1 it picks Tuesday automatically.

Your $nowtime = (hour + 2) is confusing me. If you are trying to advance time by 2 hours after each interval, that probably should be done under labels, not within the screen. In my mind, the purpose of the screen should be to 'decode' the current day and time, not to handle the advancement of time.

Handling the 'if it's past midnight, advance to next day' math in the screen might be OK though. I did something similar in my personal mod. In my case, I adjusted a few 'out of desired range' variables, so if a stat was higher than the max I wanted, it'd re-adjust to the maximum desired value, and I also had 'minimums' set up this way as well with my hud screen.
 

Cohibozz

Member
Aug 14, 2018
125
27
wihout RestartStatement() the time go ahead by 1 hour on click over the 23--24--25---etcc etc with this it reset correctly on click 23 to 0 and the day go ahead also. but it stop to work when the time reset at 0!

$ todays = "Tue" is usefull, the game calculate the day itselft it's only for declare something. i can put also $ todays = "yellow" and it work the same

pls can u share your screen to check how it works on day change?
 

OhWee

Forum Fanatic
Modder
Game Developer
Jun 17, 2017
5,662
28,506
OK, I understand your button now (Doh!). That makes sense. Time advancement was handled under various labels in Lab Rats/at the end of various dialogue trees, not by clicking a button, so the script won't help you in this case.

Not sure why resetting to 0 is locking you up. Maybe @Rich or someone else can figure this out. Also, maybe assign the 'advance time' text button to a separate screen? It's a long shot, but separating 'click for math' functions from the variable display screen may or may not help.
 

Cohibozz

Member
Aug 14, 2018
125
27
yes. but the buton work until enter in if statement. i think i've to add something in if statement to refresh screen also.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,135
14,818
Code:
        textbutton "[time]:00 - [nowfase]":
            action SetVariable("time", time + 1)
                RestartStatement()
That's not how you chain actions in a action, alternate or hovered property.
Code:
       textbutton "[time]:00 - [nowfase]":
            action [ SetVariable("time", time + 1), RestartStatement() ]
The screen action have no reason to be here.


The problem can be solved in many way. One of them is to use the screen action :
You don't have permission to view the spoiler content. Log in or register now.
The values will be directly increased from the screen.
It correctly increase the day and time, but you have no control over the fact that the day changed.

Another is, to use the screen action :
You don't have permission to view the spoiler content. Log in or register now.
Each time the button will be clicked, it will execute the content of the function. You now have more control over what happen when the day change.

Yet another one is to not rely on Python for the whole change, but on Ren'py to let you use Ren'py statements. For this use the screen action :
You don't have permission to view the spoiler content. Log in or register now.
You now have full control hover what happen when the day change. But you must return to the original game flow at the end.

But what's probably the better solution is a mix of the, already seen, If screen action, and the one.
You don't have permission to view the spoiler content. Log in or register now.
Now you have the control over both what happen when the day change, and the game flow.

Note that I have limited the change to just time and day to keep the example easy to understand. But you can easily add whatever you want. For example, in the pure If approach, you can include the update of nowfase :
Code:
            action [ If( time < 23, SetVariable("time", time + 1), [ SetVariable( "day", day + 1 ), SetVariable( "time", 0 ) ] ),
                    SetVariable( nowfase,  fasetime[ (time + 2 ) / 6) ] ) ]
Note the '[' at the start and the ']' at the end. This is not two lines, but a single line split for readability. Ren'py will understand them like this.
 
  • Like
Reactions: Shadow Fiend

Cohibozz

Member
Aug 14, 2018
125
27
Ty a lot! I ve ti try it.

I need only skiptime function, not for day or period. I think it should enought for lazy player
 

Cohibozz

Member
Aug 14, 2018
125
27
ty a lot. working good!
Code:
screen daytime:
    $ todays = "Tue"
    $ daynames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    $ todays =  daynames[(day%7)]

    $ fasetime = ["Late Night", "Morning", "Afternoon", "Evening", "Night"]
    $ nowtime = (time + 2)
    $ nowfase = fasetime[(nowtime / 6)]
    hbox:
        xalign 0.0 yalign 0.0
        textbutton "[todays]"

        textbutton "[time]:00 - [nowfase]":
            action If( time < 23, SetVariable("time", time + 1), Jump( "newDay" ))
Code:
label newDay():
    $ time = 0
    $ day += 1
jump inizio
i've last question...(for now )
the jump force me to go in specific label. can i stay in label where i'm? i think i can do a loop for daytime screen or something
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,135
14,818
the jump force me to go in specific label. can i stay in label where i'm?
Yes you can, by example by using instead of Jump :
Code:
        textbutton "[time]:00 - [nowfase]":
            action If( time < 23, SetVariable("time", time + 1), Return( "newDay" ))
But you'll need to for this.
Code:
label myLabel:
    [...]
    call screen daytime
    if _return == "newDay":
       $ time = 0
       $ day += 1
    [...]
Never really tried the Call screen action I talked about above, but it should also do the trick.
 

Cohibozz

Member
Aug 14, 2018
125
27
i've changed something and now work perfectly...i post my code for how need it

Code:
screen daytime:
    if time == 0:
        $day +=1
    $ todays = "Tue"
    $ daynames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
    $ todays =  daynames[(day%7)]

    $ fasetime = ["Late Night", "Morning", "Afternoon", "Evening", "Night"]
    $ nowtime = (time + 2)
    $ nowfase = fasetime[(nowtime / 6)]
    hbox:
        xalign 0.0 yalign 0.0
        textbutton "[todays]"

        textbutton "[time]:00 - [nowfase]":
            action If( time < 23, SetVariable("time", time + 1), SetVariable("time", 0))

the code give a time with 5 period, the player can skip time by 1 hour in game by clicking on it.
when time go to 24 is set to 0:00 and a new day come.



i've anoother questione for you....can i set this screen persistent on my game or i've to call it everytime i jump in another label?
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,135
14,818
can i set this screen persistent on my game or i've to call it everytime i jump in another label?
Er... yes :/ I don't want to seem harsh, it's really late here and my brain is already half asleep but... I don't know, your question seem strange. It's the default behavior of a screen, being shown until another one using the same replace it, or it is explicitly hidden. Just use the statement and it should do it.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,135
14,818
:) oh Jesus! I'm idiot!
No, or we all are. Some times we focus so much on something we want to achieve, that what is the more obvious completely disappear from our mind.
If it can help you, once in English class (should have been my third years learning this language) I asked how we say "I am"... It's surely one of the first things we all learned whatever our own language, but this particular day, I was completely unable to remember it ; neither the "I" nor the "am"... Not my proudest day.