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.