In a Screen, Calling a Label having variables changes the main game.[Solved]

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
Yuvan raj
Regular
Posts: 38
Joined: Wed Feb 17, 2021 11:24 am
Contact:

In a Screen, Calling a Label having variables changes the main game.[Solved]

#1 Post by Yuvan raj »

Hello guys, I have some buttons(used to see stats) on the side of the screen.

Image

When I click one of the button. A big screen shows up with stats and so on. There is a close button in this screen.

Image

When I click on the close button It hides the screen but also calls a label with several variables so that it gets reset.

But here is the problem. When I click on the close button it also changes the main game.
The below image should have been the same as the first image but it is not.
Image

I have detected the problem and it is the close button that is causing this. Without calling the label the close button doesn't affect the game. I removed the return statement in the label and still the game is affected. The calling of the label itself is causing the game to be affected.

Code: Select all

                imagebutton auto "close_%s" xpos 1125 ypos 8 action [Hide("charactersbutton"), SetVariable("characters_imagebutton_list_boolean",True), Show("statusbuttons"), Call("close_label")]

And this is the label that I'm calling in the above close button.

Code: Select all


label close_label:
    $ steve_character_imagebutton = False
    $ diana_character_imagebutton = False
    $ stacy_character_imagebutton = False
    $ robin_character_imagebutton = False
    $ brad_character_imagebutton = False

    return

I can use SetVariable on the imagebutton to change these variables instead of using a label. But it would be so long and would confusing if I want to change something. Can I know to call these variables without affecting the game. Would placing these codes inside a screen instead of the label and using Show statement in the imagebutton work?
Last edited by Yuvan raj on Wed Jul 21, 2021 9:43 am, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: In a Screen, Calling a Label having variables changes the main game.

#2 Post by Alex »

Yuvan raj wrote: Wed Jul 21, 2021 4:39 am ...
You could make a function to reset some variables and run it for close button. Something like

Code: Select all

init python:
    def reset_some_vars():
        # all neccessary variables should be listed below as global ones
        global steve_character_imagebutton, diana_character_imagebutton, stacy_character_imagebutton, robin_character_imagebutton, brad_character_imagebutton

        steve_character_imagebutton = False
        diana_character_imagebutton = False
        stacy_character_imagebutton = False
        robin_character_imagebutton = False
        brad_character_imagebutton = False

Code: Select all

imagebutton auto "close_%s" xpos 1125 ypos 8 action[ Function(reset_some_vars), Hide(), etc. ]
https://www.renpy.org/doc/html/screen_a ... l#Function

Yuvan raj
Regular
Posts: 38
Joined: Wed Feb 17, 2021 11:24 am
Contact:

Re: In a Screen, Calling a Label having variables changes the main game.

#3 Post by Yuvan raj »

Alex wrote: Wed Jul 21, 2021 6:55 am
Yuvan raj wrote: Wed Jul 21, 2021 4:39 am ...
You could make a function to reset some variables and run it for close button. Something like

Code: Select all

init python:
    def reset_some_vars():
        # all neccessary variables should be listed below as global ones
        global steve_character_imagebutton, diana_character_imagebutton, stacy_character_imagebutton, robin_character_imagebutton, brad_character_imagebutton

        steve_character_imagebutton = False
        diana_character_imagebutton = False
        stacy_character_imagebutton = False
        robin_character_imagebutton = False
        brad_character_imagebutton = False

Code: Select all

imagebutton auto "close_%s" xpos 1125 ypos 8 action[ Function(reset_some_vars), Hide(), etc. ]
https://www.renpy.org/doc/html/screen_a ... l#Function
You Sir are a Sexy beast of a man. Thank you so much. It worked!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]