Screen parameters not clearing properly

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
mtermik
Regular
Posts: 28
Joined: Fri Dec 23, 2022 2:26 pm
Contact:

Screen parameters not clearing properly

#1 Post 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)

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2410
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Screen parameters not clearing properly

#2 Post 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.
< < insert Rick Cook quote here > >

philat
Eileen-Class Veteran
Posts: 1920
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Screen parameters not clearing properly

#3 Post 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).

Post Reply

Who is online

Users browsing this forum: Google [Bot]