button action being computated before activation

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
User avatar
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

button action being computated before activation

#1 Post by nature1996 » Sun May 05, 2019 11:15 pm

Hi,

So basically, my problem is that the content of the action tag seem to be evaluated when the button is printed, not when it is activated. Long story short, I want something to append when the text of two button is combined, but it happens a soon as I see the second button if I selected the first. I can post more of the code if needed, but here is the part that is problematic:

Code: Select all

                vbox:
                    if not (current_selected.desc == []):
                        for j in current_selected.desc:
                            if (j != None) and j.active:
                                textbutton "[j.data]":
                                    text_insensitive_color gui.idle_color
                                    sensitive current_selected.end
                                    action If(current_data == None, SetVariable("current_data", j), 
                                        Function(renpy.call, "combination", j.test(current_data)))
the function test is the one that do something, but I need it to wait for the button to be selected before it happens. I tried to hide the test in another screen, thinking I had to show a screen with a message telling the player if it was a success or not, but it turns out Ren'Py also evaluated the new screen as soon as the button appeared, because I could see the effect of the test (a new button was added). The screen didn't show, and when I choose the button, it show me the text for when the combination is not a new valid one (aka "try again")

TL;DR: I need a way to test something only when the button is selected, then immediately show a feedback on the result of that test, but couldn't find how.
Je parle aussi français

User avatar
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

Re: button action being computated before activation

#2 Post by nature1996 » Mon May 06, 2019 12:35 am

It would seem option number 10 of 9 was the right one. Since the function I was calling is in python, I showed the screen from there, guessing finally that it wouldn't predict that. Anyway, I'm still curious if there is a more elegant way of doing it.
Je parle aussi français

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

Re: button action being computated before activation

#3 Post by Alex » Mon May 06, 2019 6:36 am

nature1996 wrote:
Sun May 05, 2019 11:15 pm
...TL;DR: I need a way to test something only when the button is selected, then immediately show a feedback on the result of that test, but couldn't find how.
So try to make your buttons toggle some vars to make them selected/unselected and add checking for this var in your screen. Something like this untested code

Code: Select all

screen my_scr():
    default a = False
    default b = False

    vbox:
        align (0.5, 0.5)
        textbutton "A" action ToggleScreenVariable("a", True, False)
        textbutton "B" action ToggleScreenVariable("b", True, False)

    if a and b:
        text "Done!" align (0.5,0.05)
viewtopic.php?f=8&t=26492&hilit=selected#p322596

User avatar
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

Re: button action being computated before activation

#4 Post by nature1996 » Mon May 06, 2019 10:46 am

That might work, but it's not enough for what I'm trying to do. My list of textbutton is dynamically created, and changing, and the two statement I want to combine might not even be in the same list. More so, I will have more than a few combination, so I pretty much need for that function (test) to be called when a second button is selected after the first one. I would guess my whole problem was that ren'py predict everything that has to do with screen.
Je parle aussi français

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

Re: button action being computated before activation

#5 Post by Alex » Mon May 06, 2019 12:58 pm

While yes, you can try to add a renpy.restart_interaction() to your test function to force screen update.

https://www.renpy.org/doc/html/other.ht ... nteraction

User avatar
nature1996
Regular
Posts: 62
Joined: Wed Jun 21, 2017 10:35 am
Contact:

Re: button action being computated before activation

#6 Post by nature1996 » Mon May 06, 2019 1:11 pm

That wouldn't solve the problem, only maybe make it worst as test get activated as soon as the screen update. Also, I might add that I added my screen in config.per_frame_screens already, it might be part of the problem.

Also, as I said, the problem is solved by calling Function(j.test, current_data), and putting the screen call in the called python functon. While not ideal, it does work as a workaround. Should I mark this as solved?
Je parle aussi français

Post Reply

Who is online

Users browsing this forum: No registered users