Time of the day sistem

The Insider

Member
Game Developer
May 4, 2017
144
255
Hi everyone! I have this code working:



but I don't understand how it works that when I press the time button I can go to that time of day, (like label morning for example) I was trying Jump, action Jump, call, nothing woks...
Pls Pls Pls Help me!!!
Thank you in advantage!
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,130
3,194
you are using something that's half completed so we can't really help you

not in less you are the user of that post

go look in the cookbook forum of that site there is a couple of daytime systems there

and sharing your full code what you have so far would be helpful too
 

The Insider

Member
Game Developer
May 4, 2017
144
255
you are using something that's half completed so we can't really help you

not in less you are the user of that post

go look in the cookbook forum of that site there is a couple of daytime systems there

and sharing your full code what you have so far would be helpful too
#I have putted this in the script
init python:
class day_time(object):
def __init__(self):
self.day = 1 # set this to whatever starting day is
self.weekdays = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] # arrange these so first weekday goes first
self.time_of_day = ["morning", "noon", "evening", "night"] # add or remove to increase time of day slots
self.end_of_day = self.time_of_day[-1] # automatically picks last slot as end of day

property
def weekday(self):
return self.weekdays[(self.day-1)%7]

property
def time(self):
return self.time_of_day[0]

def advance(self, increment = 0, days = 0):
if not (increment + days): # no input
increment = 1

if days: # add to increment by length of time_of_day
increment += days * len(self.time_of_day)

while increment > 0: # loop through increments to shift timeslot and days forward
if self.time_of_day[0] == self.end_of_day:
self.day += 1
self.time_of_day.append(self.time_of_day.pop(0))
increment -= 1 # reduce incrememnt to escape loop after enough runs

default clock = day_time()

label start:
stop music fadeout 1.0
$ clock.advance()

scene black
with fade

show text _("The events and characters depicted in this game are fictional. Any resemblance to actual events or persons is purely coincidental.") at truecenter

pause 6

scene black
with fade


menu:
"{color=#800000}WARNING. The game features content not intended for persons under the age of 18. Are you over 18 years old?{/color}"

"{color=#32CD32}I am over 18 years old{/color}":
jump intro
"{color=#FF0000}I am under 18 years old{/color}":
"Come back when you reach the age of 18. Have a nice day!"
return



"{b}clock.day{/b} returns Day: {b}[clock.day]{/b}"
"{b}clock.weekday{/b} returns Weekday: {b}[clock.weekday]{/b}"
"{b}clock.time{/b} returns Time of Day: {b}[clock.time]{/b}"
"{b}$ clock.advance(){/b} advances time"
$ clock.advance() # advances time by one slot
"Advanced 1 slot:\n\nDay [clock.day] ([clock.weekday]) [clock.time]"

$ clock.advance(2) # advances time by two slots
"Advanced 2 slots:\n\nDay [clock.day] ([clock.weekday]) [clock.time]"

$ clock.advance(days=1) # advances one day
"Advanced 1 day:\n\nDay [clock.day] ([clock.weekday]) [clock.time]"

$ clock.advance(1,8) # advance 8 days and one slot
"Advanced 1 slot and 8 days (note night to morning still advances addition day):\n\nDay [clock.day] ([clock.weekday]) [clock.time]"





label morn:

scene black


if clock.time=="evening":


jump evening

if clock.time=="morning":


jump morning

if clock.time=="noon":


jump noon

if clock.time=="night":


jump night

else:
return





label evening:

scene black
"evening"


label morning:

scene black
"morning"

label noon:

scene black
"noon"

label night:

scene black
"night"


#It works like this but I want that he jumps to the noon label (if it morning for example) when I push the screen button

screen day_time_map:

zorder 103

if clock.time=="morning":
add Transform("morning.png", xpos=130, ypos=62)



if clock.time=="noon":
add Transform("noon.png", zoom=.8)

if clock.time=="afternoon":
add Transform("afternoon.png", zoom=.8)
if clock.time=="evening":
add Transform("evening.png", zoom=.8)
if clock.time=="night":
add Transform("night.png", zoom=.8)



screen week_day_map:

zorder 103

if clock.weekday=="Monday":

add Transform("monday_button.png", xpos=130, ypos=12)

if clock.weekday=="Tuesday":

add Transform("tuesday_button.png", zoom=.8)

if clock.weekday=="Wednesday":

add Transform("wednesday_button.png", zoom=.8)

if clock.weekday=="Thursday":
add Transform("thursday_button.png", zoom=.8)

if clock.weekday=="Friday":

add Transform("friday_button.png", zoom=.8)

if clock.weekday=="Saturday":

add Transform("saturday_button.png", zoom=.8)

if clock.weekday=="Sunday":

add Transform("sunday_button.png", zoom=.8)
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,130
3,194
where is the button that you were talking about?

you need a textbutton or imagebutton with SetVariable() inside of a screen that you use call screen to change the time

use the ["code=python"] function on the forum it will easier to understand remove the ""["/code"]
 

The Insider

Member
Game Developer
May 4, 2017
144
255
where is the button that you were talking about?

you need a textbutton or imagebutton with SetVariable() inside of a screen that you use call screen to change the time

use the ["code=python"] function on the forum it will easier to understand remove the ""["/code"]
This is my text button:
screen time:

tag navscreen
imagemap:

vbox:
textbutton "{b}[clock.time] [clock.weekday]{/b}" action Function(clock.advance)
if clock.time == "Night":
idle "night.png"


else:
idle "morning.png"
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,130
3,194
here is yours

textbutton "{b}[clock.time] [clock.weekday]{/b}" action Function(clock.advance)
and this from kivik in


Python:
textbutton "{b}[clock.time] [clock.weekday]{/b}" action Function(clock.advance())
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,234
Python:
textbutton "{b}[clock.time] [clock.weekday]{/b}" action Function(clock.advance())
This is wrong, totally wrong. It call the advance method when the screen is displayed, while doing absolutely nothing when the button is pressed.
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,130
3,194
This is wrong, totally wrong. It call the advance method when the screen is displayed, while doing absolutely nothing when the button is pressed.
I never said I was right first place maybe she has to read the thread that she got it from again


Python:
textbutton "{b}[clock.time] [clock.weekday]{/b}" action Function(clock.advance, 7)

or

textbutton "{b}[clock.time] [clock.weekday]{/b}" action SetVariable(clock.advance, 7)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,978
16,234
Python:
textbutton "{b}[clock.time] [clock.weekday]{/b}" action Function(clock.advance, 7)
[/QUOTE]

This one don't change much.
The code for the [icode]advance[/icode] method show that it will proceed with one unit of increment in case no value is passed as argument. Therefore his button is correct.



Hard to see what's wrong with the code totally unreadable due to the lack of indentation, but one thing caught my eyes:
[QUOTE="HappyMO, post: 9243764, member: 23972"]
[code=python]
        def advance(self, increment = 0, days = 0):
           if not (increment + days): # no input
               increment = 1

           if days: # add to increment by length of time_of_day
               increment += days * len(self.time_of_day)

            while increment > 0: # loop through increments to shift timeslot and days forward
               if self.time_of_day[0] == self.end_of_day:
                   self.day += 1
               self.time_of_day.append(self.time_of_day.pop(0))
               increment -= 1 # reduce incrememnt to escape loop after enough runs
By itself the code works, but what the fucking fuck, rarely seen so over complicated code for something so simple

This would do the same while being way easier to understand, and therefore to deal with:
Python:
    class day_time(object):
       def __init__(self):
           [...]
           #self.end_of_day = self.time_of_day[-1]   Now totally useless
           self.tod = 0

       [...]

       @property
       def time(self):
           return self.time_of_day[self.tod]

       def advance(self, increment = 1, days = 0):
           self.day += days
           self.tod += increment

           while self.tod > len( self.time_of_day ):
               self.day += 1
               self.tod -= len( self.time_of_day )
 
  • Like
Reactions: The Insider

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,130
3,194
well here this might more simple to use and to understand

tested and it works

that's if you want to do it this way

it doesn't Sunday to Saturday but it can be put into it

time.rpy
Python:
screen dayinfo:
    zorder 4
    if wd == 1:
        $ weekday = _("Sunday")
    elif wd == 2:
        $ weekday = _("Monday")
    elif wd == 3:
        $ weekday = _("Tuesday")
    elif wd == 4:
        $ weekday = _("Wednesday")
    elif wd == 5:
        $ weekday = _("Thursday")
    elif wd == 6:
        $ weekday = _("Friday")
    elif wd == 7:
        $ weekday = _("Saturday")

    if dn > 24:
        $ dn = 0
    if dn > 0 and dn < 5:
        $ daytime = _("MORNING")
        $ daytimejump = 5
    elif dn > 4 and dn < 10:
        $ daytime = _("AFTERNOON")
        $ daytimejump = 10
    elif dn > 9 and dn < 16:
        $ daytime = _("EVENING")
        $ daytimejump = 16
    elif dn > 16:
        $ daytime = _("NIGHT")
    $ dn_show = dn + 7
    if dn_show > 23:
        $ dn_show = dn - 17

    vbox:
        xalign 0.01
        yalign 0.01
        hbox:
            textbutton _("DAY"):
                text_color "#eddbc3"
                text_size 40
                text_hover_outlines [(3, "#cc0000", 0, 0)]
                text_idle_outlines [(3, "#111111", 0, 0)]
                text_font "font/foo_regular.ttf"
                action If (block_day_button,None,(SetVariable("dn", 0)))
            null width 2
            text str(daynum):
                size 40
                outlines [(3, "#222222", 0, 0)]
                font "font/foo_regular.ttf"

        null height -10
        textbutton str(daytime):
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            if _preferences.language == "korean":
                text_font 'font/NanumBarunGothic.ttf'
            else:
                text_font "font/foo_regular.ttf"
            action If (block_day_button,None,(If(dn < 16, (SetVariable("dn", daytimejump)), None)))
        null height -10
        textbutton str(weekday):
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            if _preferences.language == "korean":
                text_font 'font/NanumBarunGothic.ttf'
            else:
                text_font "font/foo_regular.ttf"
            if wd == 7:
                action SetVariable("wd", 1)
            else:
                action SetVariable("wd", wd + 1)
        null height -10
        textbutton "[dn_show]:00":
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            text_font "font/foo_regular.ttf"
            action If (block_day_button,None,(If(dn<20, (SetVariable("dn", dn + 1)), None)))
script.rpy
change anything init to default
Python:
init:
    $ dn = 16
    $ daynum = 1
    $ daytimejump = 0
    $ daytime = _("NIGHT")
    $ weekday = _("Sunday")
    $ wd = 1

label start:
    $ block_day_button = False # True is turn off buttons
    show screen dayinfo
    return
fonts that is needed
View attachment font.rar

I have update it to work weekdays
 
Last edited:

The Insider

Member
Game Developer
May 4, 2017
144
255
well here this might more simple to use and to understand

tested and it works

that's if you want to do it this way

it doesn't Sunday to Saturday but it can be put into it

time.rpy
Python:
screen dayinfo:
    zorder 4
    if wd == 1:
        $ weekday = _("Sunday")
    elif wd == 2:
        $ weekday = _("Monday")
    elif wd == 3:
        $ weekday = _("Tuesday")
    elif wd == 4:
        $ weekday = _("Wednesday")
    elif wd == 5:
        $ weekday = _("Thursday")
    elif wd == 6:
        $ weekday = _("Friday")
    elif wd == 7:
        $ weekday = _("Saturday")

    if dn > 24:
        $ dn = 0
    if dn > 0 and dn < 5:
        $ daytime = _("MORNING")
        $ daytimejump = 5
    elif dn > 4 and dn < 10:
        $ daytime = _("AFTERNOON")
        $ daytimejump = 10
    elif dn > 9 and dn < 16:
        $ daytime = _("EVENING")
        $ daytimejump = 16
    elif dn > 16:
        $ daytime = _("NIGHT")
    $ dn_show = dn + 7
    if dn_show > 23:
        $ dn_show = dn - 17

    vbox:
        xalign 0.01
        yalign 0.01
        hbox:
            textbutton _("DAY"):
                text_color "#eddbc3"
                text_size 40
                text_hover_outlines [(3, "#cc0000", 0, 0)]
                text_idle_outlines [(3, "#111111", 0, 0)]
                text_font "font/foo_regular.ttf"
                action If (block_day_button,None,(SetVariable("dn", 0)))
            null width 2
            text str(daynum):
                size 40
                outlines [(3, "#222222", 0, 0)]
                font "font/foo_regular.ttf"

        null height -10
        textbutton str(daytime):
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            if _preferences.language == "korean":
                text_font 'font/NanumBarunGothic.ttf'
            else:
                text_font "font/foo_regular.ttf"
            action If (block_day_button,None,(If(dn < 16, (SetVariable("dn", daytimejump)), None)))
        null height -10
        textbutton str(weekday):
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            if _preferences.language == "korean":
                text_font 'font/NanumBarunGothic.ttf'
            else:
                text_font "font/foo_regular.ttf"
            if wd == 7:
                action SetVariable("wd", 1)
            else:
                action SetVariable("wd", wd + 1)
        null height -10
        textbutton "[dn_show]:00":
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            text_font "font/foo_regular.ttf"
            action If (block_day_button,None,(If(dn<20, (SetVariable("dn", dn + 1)), None)))
script.rpy
change anything init to default
Python:
init:
    $ dn = 16
    $ daynum = 1
    $ daytimejump = 0
    $ daytime = _("NIGHT")
    $ weekday = _("Sunday")
    $ wd = 1

label start:
    $ block_day_button = False # True is turn off buttons
    show screen dayinfo
    return
fonts that is needed
View attachment 2124833

I have update it to work weekdays
Omg!!!:love::love::love: thank you so much!!!
I wasted a week figuring out that code and almost nothing to get me to the point I wanted. Again, thank you so much!!!
 
  • Like
Reactions: rayminator

The Insider

Member
Game Developer
May 4, 2017
144
255
well here this might more simple to use and to understand

tested and it works

that's if you want to do it this way

it doesn't Sunday to Saturday but it can be put into it

time.rpy
Python:
screen dayinfo:
    zorder 4
    if wd == 1:
        $ weekday = _("Sunday")
    elif wd == 2:
        $ weekday = _("Monday")
    elif wd == 3:
        $ weekday = _("Tuesday")
    elif wd == 4:
        $ weekday = _("Wednesday")
    elif wd == 5:
        $ weekday = _("Thursday")
    elif wd == 6:
        $ weekday = _("Friday")
    elif wd == 7:
        $ weekday = _("Saturday")

    if dn > 24:
        $ dn = 0
    if dn > 0 and dn < 5:
        $ daytime = _("MORNING")
        $ daytimejump = 5
    elif dn > 4 and dn < 10:
        $ daytime = _("AFTERNOON")
        $ daytimejump = 10
    elif dn > 9 and dn < 16:
        $ daytime = _("EVENING")
        $ daytimejump = 16
    elif dn > 16:
        $ daytime = _("NIGHT")
    $ dn_show = dn + 7
    if dn_show > 23:
        $ dn_show = dn - 17

    vbox:
        xalign 0.01
        yalign 0.01
        hbox:
            textbutton _("DAY"):
                text_color "#eddbc3"
                text_size 40
                text_hover_outlines [(3, "#cc0000", 0, 0)]
                text_idle_outlines [(3, "#111111", 0, 0)]
                text_font "font/foo_regular.ttf"
                action If (block_day_button,None,(SetVariable("dn", 0)))
            null width 2
            text str(daynum):
                size 40
                outlines [(3, "#222222", 0, 0)]
                font "font/foo_regular.ttf"

        null height -10
        textbutton str(daytime):
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            if _preferences.language == "korean":
                text_font 'font/NanumBarunGothic.ttf'
            else:
                text_font "font/foo_regular.ttf"
            action If (block_day_button,None,(If(dn < 16, (SetVariable("dn", daytimejump)), None)))
        null height -10
        textbutton str(weekday):
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            if _preferences.language == "korean":
                text_font 'font/NanumBarunGothic.ttf'
            else:
                text_font "font/foo_regular.ttf"
            if wd == 7:
                action SetVariable("wd", 1)
            else:
                action SetVariable("wd", wd + 1)
        null height -10
        textbutton "[dn_show]:00":
            xalign 0.5
            text_color "#ffffff"
            text_size 25
            text_hover_outlines [(3, "#cc0000", 0, 0)]
            text_idle_outlines [(3, "#111111", 0, 0)]
            text_font "font/foo_regular.ttf"
            action If (block_day_button,None,(If(dn<20, (SetVariable("dn", dn + 1)), None)))
script.rpy
change anything init to default
Python:
init:
    $ dn = 16
    $ daynum = 1
    $ daytimejump = 0
    $ daytime = _("NIGHT")
    $ weekday = _("Sunday")
    $ wd = 1

label start:
    $ block_day_button = False # True is turn off buttons
    show screen dayinfo
    return
fonts that is needed
View attachment 2124833

I have update it to work weekdays
Maybe I'm dumb, but I don't figure out how can I jump to next day from label without pressing the weekday button and reset the time to morning when I get to the next label without the "DAY" button.


something like this:
label sunday:
if is 3:00
"Go to sleep"
jump monday

label monday:
clock reset or something

Pls Help me!!!
 

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,130
3,194
the code that I gave you is from My Cute Roommate by the way

this how to change look at # how to change

Python:
init:

    $ dn = 16 this changes hour of the day
   # $ dn += 1 or $ dn -= 1

    $ daynum = 1 this changes the number days went by
  #  $ daynum += 1 or $ daynum -= 1

    $ wd = 1  this changes the week day
  #  $ wd += 1  or $ wd -= 1 anything that from 1 to 7 Sun to Sat
  

    $ daytime = _("NIGHT") this is just a placeholder if statements
     this controlled by dn variable

    $ weekday = _("Sunday") this is just a placeholder if statements
    this controlled by wd variable
so if you want it to be Monday you would do this $ wd = 2

Python:
label sunday:
    if dn == 3:
        "Go to sleep"
        $ wd = 2
        jump monday
 
Last edited:

The Insider

Member
Game Developer
May 4, 2017
144
255
the code that I gave you is from My Cute Roommate by the way

this how to change look at # how to change

Python:
init:

    $ dn = 16 this changes hour of the day
   # $ dn += 1 or $ dn -= 1

    $ daynum = 1 this changes the number days went by
  #  $ daynum += 1 or $ daynum -= 1

    $ wd = 1  this changes the week day
  #  $ wd += 1  or $ wd -= 1 anything that from 1 to 7 Sun to Sat
 

    $ daytime = _("NIGHT") this is just a placeholder if statements
     this controlled by dn variable

    $ weekday = _("Sunday") this is just a placeholder if statements
    this controlled by wd variable
so if you want it to be Monday you would do this $ wd = 2

Python:
label sunday:
    if dn == 3:
        "Go to sleep"
        $ wd = 2
        jump monday
I have figure it out at last, Thank you again!!!