Keep showing dialogbox until imagebuttons are 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
newbiemate
Regular
Posts: 85
Joined: Tue Dec 19, 2017 1:36 pm
Contact:

Keep showing dialogbox until imagebuttons are clicked?

#1 Post by newbiemate »

Normally a dialogbox will disappear once the user clicks the viewport in order to progress forward with the game. However, I wanted to add more interactivity by asking the player a question and having the player pick a couple of options (represented as imagebuttons).

The issue is, when the dialog has loaded all the text, as soon as the player clicks on the screen the dialog goes away. It will then display the buttons, but I would like the dialog to stay until the player has clicked on a button.

Here is a demo:

Code: Select all

screen show_buttons:
    imagebutton:
         xpos 300
         ypos 300
         idle "images/chair.png"
         action Return("chair")
    imagebutton:
         xpos 500
         ypos 300
         idle "images/table.png"
         action Return("table")

label start:
    default me = Character("Me")
    
    ## !!  Problem: when user clicks on screen, this dialog disappears, but I would like it to stay until a button has been clicked.
    me "Please pick what you think is a table!"  
    
    show screen show_buttons
    result = ui.interact()
    
    if result == 'chair':
        me "You selected Chair... not quite right!"
    if result == 'table':
        me "You selected Table... correct!"

    return
Is there a way I can make the dialog stay and then hide it after the user has picked something?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Keep showing dialogbox until imagebuttons are clicked?

#2 Post by Imperf3kt »

ui.interact is old and deprecated (though still used internally by renpy)
Try this instead

Code: Select all

 
screen show_buttons:
    modal True
    
    imagebutton:
         xpos 300
         ypos 300
         idle "images/chair.png"
         action Return("chair")
    imagebutton:
         xpos 500
         ypos 300
         idle "images/table.png"
         action Return("table")

default me = Character("Me")


label start:
    
    show screen show_buttons
    me "Please pick what you think is a table!"  
    
    if _return == 'chair':
        me "You selected Chair... not quite right!"
    if _return == 'table':
        me "You selected Table... correct!"

    return
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

newbiemate
Regular
Posts: 85
Joined: Tue Dec 19, 2017 1:36 pm
Contact:

Re: Keep showing dialogbox until imagebuttons are clicked?

#3 Post by newbiemate »

Thank you! Can you explain two things, so I can understand a bit better?

1) What does modal True do, and is it always needed when building imagebutton menus?

2) I did this to see what _return was giving me:

Code: Select all

me "Please pick what you think is a table!" 
$ print(_return)
But this is printing None, so it never executes the if statements. Do you know why this is?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Keep showing dialogbox until imagebuttons are clicked?

#4 Post by Imperf3kt »

_return should return the value set in Return()
I've only ever used it with called screens, perhaps it doesn't work with shown screens.

modal True ensures the player cannot advance the dialogue without clicking the buttons (which I forgot to add a Hide screen action to)

I don't have much time to write out a better example, so I'm attaching part of a project I'm currently working on in which uses an almost identical mechanism. Maybe it can give you some ideas?
script.txt
(8.94 KiB) Downloaded 13 times
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

newbiemate
Regular
Posts: 85
Joined: Tue Dec 19, 2017 1:36 pm
Contact:

Re: Keep showing dialogbox until imagebuttons are clicked?

#5 Post by newbiemate »

Ah thanks, I'll take a look. I was also going over my code and I feel like something is fundamentally not correct...

I found out why I'm getting None. It's because I use show screen instead of call screen:
If the screen was called using the call screen statement, the return value is placed in the _return variable.
However, if I switch it to call screen, then the dialogue will show, but will disappear when I click on the screen, and then the buttons will show.

So instead of returning, I decided I would Call another label and handle the logic separately. This kind of worked, but the logic never returns to the calling label:

Code: Select all

screen show_buttons:
    modal True
    
    imagebutton:
         xpos 300
         ypos 300
         idle "images/chair.png"
         action [Call("chair"), Return()]
    imagebutton:
         xpos 500
         ypos 300
         idle "images/table.png"
         action [Call("table"), Return()]

label chair():
    me "You selected Chair... not quite right!"
    return
    
label table():
    me "You selected Table... correct!"
    return

default me = Character("Me")

label start:
    
    show screen show_buttons
    me "Please pick what you think is a table!"  
    
    $ result = _return

    "Okay, done!"

    return
When I click on any of the buttons, it correctly calls the labels and I see the dialog change to their respective text, but then after it waits for user input again. Clicking on any button just repeats the interaction infinitely... It never actually returns and I never see "Okay, done!", and the game never ends.

I guess I'm missing something.. does [Call("chair"), Return()] not return control to $ result = _return? I feel like I'm digging the hole deeper now.

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

Re: Keep showing dialogbox until imagebuttons are clicked?

#6 Post by philat »

Why wouldn't you just use SetVariable instead of trying to return the value?

Post Reply

Who is online

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