functionbuttonrenpy

Renpy Clock skip time button


I am trying to create a textbutton when clicked will advance time on a simple clock.

In my script.rpy file I have.

label start:

    show screen timeclock #shows time & day on screen
    return

I then created a clock.rpy file for my clock screen and logic.

define day = 1
define clock = 7


# Display Time and Day
screen timeclock():
    vbox:
        xpos 0.0
        yalign 0.0

        text _("Time: [clock]:00") size 40
        text _("Day: [day]") size 30
        textbutton _("Wait 1-Hour"):
            action Null   #<<< This needs to be correctTime
            text_size 10


correctTime:  #<<< This needs to be button action
    if clock <= 22:
        $clock += 1
    else:
        $clock = 0
        $day += 1

How can I make the textbutton on click do correctTime logic? Thanks for your time.


Solution

  • I solved the issue. Clock.rpy

    define day = 1
    define clock = 7
    
    
    # Display Time and Day
    screen timeclock():
        vbox:
            xpos 0.0
            yalign 0.0
    
            text _("Time: [clock]:00") size 40
            text _("Day: [day]") size 30
            textbutton _("Wait 1-Hour"):
                action Function(correctTime)
                text_size 10
    
    init python:
        def correctTime():
            global day
            global clock
            if clock <= 22:
                clock += 1
            else:
                clock = 0
                day += 1