SetScreenVariable doesn't work in a "used" screen?
Posted: Tue Jun 26, 2018 1:11 pm
I'm using Renpy 7.0.0.196. I have a screen that I plan to re-use in several places that makes use of an internal screen variable, which changes based on actions the player takes and, in turn, allows the screen to alter itself. Using a SetScreenVariable action works just fine if I call the screen directly, but if I "use" the screen inside another and then call the "parent" screen, either (a) SetScreenVariable has no effect, or else (b) the screen doesn't update itself as a result the way it does if called directly.
Is this intended? Or am I doing something wrong?
Below is a greatly simplified, self-contained script that illustrates the issue. When the "child" screen is called directly, the SetScreenVariable actions update the "state" variable, causing the "ping" and "pong" buttons to alternate. However, when the "parent" screen is called (which "uses" the child screen), clicking on "ping" does not cause the "state" screen variable to change. (Or, if it does, the screen does not update to reflect that fact.)
If I use a global variable and use SetVariable instead of SetScreenVariable, then both versions behave as expected, but that really isn't what I'd prefer to do.
Is this intended? Or am I doing something wrong?
Below is a greatly simplified, self-contained script that illustrates the issue. When the "child" screen is called directly, the SetScreenVariable actions update the "state" variable, causing the "ping" and "pong" buttons to alternate. However, when the "parent" screen is called (which "uses" the child screen), clicking on "ping" does not cause the "state" screen variable to change. (Or, if it does, the screen does not update to reflect that fact.)
Code: Select all
image bg = "#888"
label start:
scene bg
"First, calling the screen directly (press 'Return' when done)"
call screen child
"Now, calling the screen indirectly"
call screen parent
"Why the difference?"
return
style button_text:
color "#f00"
hover_color "#ff0"
screen child():
default state = 0
text "State: [state]" align(0.0,0.0)
textbutton "Return":
align(1.0,0.0)
action Return()
if state == 0:
textbutton "ping":
align (0.25,0.5)
action SetScreenVariable("state", 1)
if state == 1:
textbutton "pong":
align (0.75,0.5)
action SetScreenVariable("state", 0)
screen parent():
text "Parent" align(0.5,0.0)
use child