How to show text on a screen with textbutton?

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
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

How to show text on a screen with textbutton?

#1 Post by Imperf3kt »

After wording this dozens of times, screw the technical crap and long-winded explanation. I'm in a bad mood after reading the 'documentation'

How do I make a textbutton that displays text below it when clicked?
I need multiple buttons on a screen that each show a different block of text when clicked.

I'm currently using this, which doesn't damn well work, clicking the button takes me to the start label, and I must keep hovering the textbutton for the text to show. Also, I hate the new way of doing tooltips. Just thought I'd mention that. Why was it ever changed? Its so confusing now.

Code: Select all

textbutton _("Pancakes") action NullAction tooltip "135g/4¾oz plain flour\n1 tsp baking powder\n½ tsp salt\n2 tbsp caster sugar\n130ml/4½fl oz milk\n1 large egg, lightly beaten\n2 tbsp olive oil"
        
        $ tooltip = GetTooltip()

        if tooltip:
            text "[tooltip]"
            
            
Here's the project folder, incase it is of use to anyone.
Hopefully this makes it a little easier to understand why I can't use a simple screen within the screen.
https://puu.sh/zPOTF/a4f849f32f.zip
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

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to show text on a screen with textbutton?

#2 Post by Remix »

Is it ok to just throw it all in one screen?

Code: Select all

screen buttons_and_text():
    default recipe = 0
    default btns = [
        _(""), _(""),
        _('Pancakes'), _("135g/4¾oz plain flour\n1 tsp baking powder\n½ tsp salt\n2 tbsp caster sugar\n130ml/4½fl oz milk\n1 large egg, lightly beaten\n2 tbsp olive oil"),
        _('Lardies'), _("135g/4¾oz lard\n1 tsp more lard\n½ tsp lard extract\n2 tbsp condensed lard\n130ml/4½fl liquid lard"),
    ]
    fixed:
        vbox:
            hbox:
                for idx in range(0, len(btns), 2):
                    textbutton btns[idx] or "Clear":
                        action [ SetScreenVariable("recipe", idx),
                                 Function( renpy.restart_interaction ) ]
            text btns[recipe+1]

label start:
    show screen buttons_and_text
    "..."
Frameworks & Scriptlets:

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

Re: How to show text on a screen with textbutton?

#3 Post by Imperf3kt »

Some of the stuff in the scripts are left in there by accident, but I highly appreciate you taking a look.
Your addition of lardies, in particular, helped restore a little morale :)

I'll give it a try right now, and hopefully once I've slept I can make sense of how it does what it does - I ran out of caffeine.

Edit:
That'll work nicely, thanks.
I'll wait until I'm less 90% asleep, to work out how you did it.

Thanks.
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

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to show text on a screen with textbutton?

#4 Post by Remix »

On an aside, I did try by using a dictionary:

Code: Select all

default btns = {
    _('Pancakes') : _("135g/4¾oz plain flour\n1 tsp baking powder"),
    _('Lardies') : _("135g/4¾oz lard\n1 tsp more lard\n½ tsp lard e..."),
}
except setting the screen variable to the key seemed to pre-translate it so the key was then not found (as "Pancakes" is not _("Pancakes") )

Hence using just a list and an incremental idx that steps by 2...
for idx in range(0, len(btns), 2) >>> for idx in (0, 2, 4, 6, ... len(the list) )
Frameworks & Scriptlets:

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

Re: How to show text on a screen with textbutton?

#5 Post by Imperf3kt »

Coming back to this because I made some modifications that I find a bit easier to understand.
The results are pretty much the same (not yet styled):
Image

For anyone interested:

Code: Select all

## Cooking screen ###############################################################
##

screen cooking():
    
    default recipe = None
    modal True
    tag menu
    style_prefix "cooking_menu"
    add gui.screens_menu_background
    
    vbox:
        add gui.menu_cooking_text
        xalign 0.5
        ypos 25
        
    vbox:
        
        xpos gui.screens_xpos
        ypos gui.screens_ypos
        
        fixed:
            vbox:
                for cooking_recipe in recipe_list:
                    textbutton cooking_recipe.name:
                        action (SetScreenVariable(name='recipe', value= cooking_recipe))

                vbox:
                    if recipe:
                        add recipe.pic
                    else:
                        pass


                vbox:
                    if recipe:
                        text recipe.desc
                    else:
                        pass
                    
        
    use navi

style cooking_menu_vbox:
    xmaximum 680
    
style cooking_menu_text:
    size gui.cooking_menu_text_size
    color gui.credit_menu_text_color
    
    
init python:
    class Item(object):
        def __init__(self, name, desc, pic):
            self.name = name
            self.desc = desc
            self.pic = pic

define pancakes = Item("Pancakes", "Blend all ingredients - probably in a blender, spoon onto a hot frying pan and hope it turns out okay.\nRemove from heat once curtains are on fire.\n\nExtinguish curtains.", "pancakes.jpg")
define cake = Item("A lie", "A delicious cake.\nYou will never get to eat it...", "cake.jpg")
default recipe_list = [pancakes, cake]
Adding new items is as simple as defining the item and adding it to recipe_list with a comma separator.
Changing the position or styling items, can be done in the usual way.
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

Post Reply

Who is online

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