Page 1 of 1

Screen parameters not clearing properly

Posted: Wed Apr 10, 2024 3:24 pm
by mtermik
Calling a screen such as:

Code: Select all

screen test(character):
And from within the screen printing out the character's name yields me:

Code: Select all

John Smith
John Smith
John Smith
This is concerning as there is no reason for a single call to the screen to result in the underlying framework actually making multiple calls. At least it has the correct character though. But only on the first call to the screen. On subsequent calls to the screen I see it start to print things such as:

Code: Select all

John Smith
John Smith
Nancy Drew
Nancy Drew
John Smith
Nancy Drew
Why I am seeing John Smith again when I pass the character of Nancy Drew is beyond me, as it shouldn't be retaining parameters after the screen has been closed and recalled. Yet again at least the last entry is the right character. Another call with John Smith, while giving me a long print out with many Nancy Drew's mixed in lands on John Smith as the last entry and so displays properly. However, this is where it starts to mess up and I start to see odd behavior. The next call to the screen with Nancy Drew results in:

Code: Select all

Nancy Drew
John Smith
Nancy Drew
Nancy Drew
John Smith
Nancy Drew
John Smith
John Smith
Nancy Drew
John Smith
Nancy Drew
Nancy Drew
Nancy Drew
John Smith
The last entry being John Smith makes the screen display improperly as it is retaining the wrong character at the end. Can anyone help me understand what is going on here?

Here is the full screen code that is producing these results:

Code: Select all

screen test(character):
    layer "test"

    if (character is not None):
        $ print (character.name)

Re: Screen parameters not clearing properly

Posted: Wed Apr 10, 2024 4:26 pm
by Ocelot
Screens should not have any side effects in their code. Screen code is run multiple times during prediction and every time screen refreshes (basically, when anything happens) and can be executed with any parameters, including those you never tried to pass.

Re: Screen parameters not clearing properly

Posted: Wed Apr 10, 2024 8:07 pm
by philat
https://www.renpy.org/doc/html/screens.html

More documentation on what Ocelot says above. More specifically, anything you want to happen in a screen should be a ScreenAction (e.g., SetVariable rather than directly manipulating a variable).