CREATE YOUR AI CUM SLUT ON CANDY.AI TRY FOR FREE
x

Ren'Py [SOLVED]screen if condition doesn't work

riktor

Active Member
Nov 26, 2018
906
1,161
try overwriting with the attached file, I did some converting from my vars to yours. can't test it much on my end without all the code to whatever you're working on though
 
  • Like
Reactions: Hetaneko

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
11,010
16,297
im going to add +1 hour with label too and its not gonna work because its resets just when you click wait...
It don't reset :
Code:
default time_hour = 0
default is_am = False

screen myGui():
    frame:
        hbox:
            textbutton "wait" action If( time_hour < 12,
                    SetVariable( "time_hour", time_hour +1 ),
                    [ SetVariable( "time_hour", 0 ), ToggleVariable( "is_am" ) ]  )
            text "Time=[time_hour]"
            if is_am is True:
                text "AM"
            else:
                text "PM"
            textbutton "return" action Return()

label start:

    call screen myGui
    "time [time_hour]"
    $ time_hour += 1
    "time [time_hour]"
    call screen myGui
    "time [time_hour]"
Anyway, if you really want it to works with both screen and label, then use a function :
Code:
init python:
    def incHour( step=1 ):
        store.time_hour += step
        if store.time_hour > 12:
            store.time_hour = 1
            store.is_am = not is_am

default time_hour = 0
default is_am = False

screen myGui():
    frame:
        hbox:
            textbutton "wait" action Function( incHour )
            text "Time=[time_hour]"
            if is_am is True:
                text "AM"
            else:
                text "PM"
            textbutton "return" action Return()

label start:

    call screen myGui
    "time [time_hour]"
    $ incHour()
    "time [time_hour]"
    call screen myGui
    "time [time_hour]"

addressing his vars in a global context seemed the only way to make his initial if statements / var setting function the way he wanted without re-writing the entire thing.
It didn't worked because of the way Ren'py deal with screens. The whole code was either out of an interaction (screen shown as an overlay(-like)) or inside a single one (screen called), and ended stuck between 0 and 12 because of this. When the screen was refreshed, the if was played, but due to the way Ren'py works, outside of the screen the value was still 12 ; so at the next refresh of the screen, the if was triggered again, and again, and again.
It would have been the same whatever the way you reference the variable. The only way to make it works was to use SetVariable to also reset the value, which force Ren'py to see it as an interaction, and so effectively update the value outside of the screen.
It also works with Function for the same reason ; Ren'py reset its context after the function, and so update the value.
 
  • Like
Reactions: Hetaneko

Hetaneko

Newbie
Apr 26, 2018
32
31
try overwriting with the attached file, I did some converting from my vars to yours. can't test it much on my end without all the code to whatever you're working on though
i did this before but its not works at label...

It don't reset :
Code:
default time_hour = 0
default is_am = False

screen myGui():
    frame:
        hbox:
            textbutton "wait" action If( time_hour < 12,
                    SetVariable( "time_hour", time_hour +1 ),
                    [ SetVariable( "time_hour", 0 ), ToggleVariable( "is_am" ) ]  )
            text "Time=[time_hour]"
            if is_am is True:
                text "AM"
            else:
                text "PM"
            textbutton "return" action Return()

label start:

    call screen myGui
    "time [time_hour]"
    $ time_hour += 1
    "time [time_hour]"
    call screen myGui
    "time [time_hour]"
Anyway, if you really want it to works with both screen and label, then use a function :
Code:
init python:
    def incHour( step=1 ):
        store.time_hour += step
        if store.time_hour > 12:
            store.time_hour = 1
            store.is_am = not is_am

default time_hour = 0
default is_am = False

screen myGui():
    frame:
        hbox:
            textbutton "wait" action Function( incHour )
            text "Time=[time_hour]"
            if is_am is True:
                text "AM"
            else:
                text "PM"
            textbutton "return" action Return()

label start:

    call screen myGui
    "time [time_hour]"
    $ incHour()
    "time [time_hour]"
    call screen myGui
    "time [time_hour]"



It didn't worked because of the way Ren'py deal with screens. The whole code was either out of an interaction (screen shown as an overlay(-like)) or inside a single one (screen called), and ended stuck between 0 and 12 because of this. When the screen was refreshed, the if was played, but due to the way Ren'py works, outside of the screen the value was still 12 ; so at the next refresh of the screen, the if was triggered again, and again, and again.
It would have been the same whatever the way you reference the variable. The only way to make it works was to use SetVariable to also reset the value, which force Ren'py to see it as an interaction, and so effectively update the value outside of the screen.
It also works with Function for the same reason ; Ren'py reset its context after the function, and so update the value.
okay... that worked! thank you for all, sorry guys for wasting your time and i hope this will help to someone.
Thanks...
 

riktor

Active Member
Nov 26, 2018
906
1,161
i did this before but its not works at label...



okay... that worked! thank you for all, sorry guys for wasting your time and i hope this will help to someone.
Thanks...
Sorry to not be of more help, glad it worked out though.