How to tell which textbutton was clicked ?

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
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

How to tell which textbutton was clicked ?

#1 Post by DrGonzo »

Hi,
I am displaying reaction choices to the player via textbuttons.
But how can I tell which textbutton was pressed?
The number of choices can vary btw, depending on the topic.

Searched around for this but couldn't find an answer.
Any help (beyond just a docu URL) would be appreciated.

- Kay


Code: Select all

    $ myInput = ["Should I come along this time?","I think I better leave!", "I guess.."]
    show screen textbutton_screen(myInput)

Code: Select all

screen textbutton_screen(mytextbuttons):
    vbox:
        for button in mytextbuttons:
            textbutton button:           
                action NullAction()
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

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

Re: How to tell which textbutton was clicked ?

#2 Post by Ocelot »

Add some action to your button, which you will use to do stuff which supposed to happen when button is pressed. One example:

Code: Select all

screen textbutton_screen(mytextbuttons):
    vbox:
        for n, button in enumerate(mytextbuttons):
            textbutton button:           
                action Return(n)

    $ myInput = ["Should I come along this time?","I think I better leave!", "I guess.."]
    call screen textbutton_screen(myInput)
    if _result == 0:
        "Should I come along this time? button was pressed"
    elif _result == 1:
        "I think I better leave! button was pressed"
    else:
        "I guess.. button was pressed"
< < insert Rick Cook quote here > >

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: How to tell which textbutton was clicked ?

#3 Post by DrGonzo »

Hi and thanks for the quick reply!

I have added this code, but I'm getting an error when I run it.
I'm assuming that everything starting at: $ myInput = ["Should I come...
goes into the script file.
Does _result need to be declared in there?

Thanks!

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 94, in script
    if _result == 0:
  File "game/script.rpy", line 94, in <module>
    if _result == 0:
NameError: name '_result' is not defined
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: How to tell which textbutton was clicked ?

#4 Post by DrGonzo »

Oh, never mind.
I've googled it and it is _return.

Now its working great - thanks so much!

- Kay
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

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

Re: How to tell which textbutton was clicked ?

#5 Post by Ocelot »

Sigh. I cannot remember proper name for that variable. Replace all instances of _result with _return. You do not need to define it, RenPy does this automatically and places in it results of RenPy call statements.
< < insert Rick Cook quote here > >

User avatar
DrGonzo
Regular
Posts: 46
Joined: Fri Feb 23, 2018 9:12 pm
Location: Los Angeles, California
Contact:

Re: How to tell which textbutton was clicked ?

#6 Post by DrGonzo »

Got it.
Thanks for your help!
Google search: "renpy thisismyquestion -org"
This gives you everything - except renpy.org results. Which I find useless 90% of the time.

Post Reply

Who is online

Users browsing this forum: No registered users