Display text on custom screen

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
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Display text on custom screen

#1 Post by TellerFarsight »

I want to make a custom screen that is just a viewport that holds text, and the text is variable.
How do I make the screen take variable text, and then how do I supply that text when showing the screen?
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: Display text on custom screen

#2 Post by Imperf3kt »

The exact way to do it depends on what you mean by the text is variable.
Does a player input it?
Is it stats?
Is it story related?
Is it random factoids in a tickertape?

One way to accomplish all of the above is to use square brackets []

Code: Select all

define "sugoi" = "awesome"

label start:
    "Wow, that was [sugoi]"
So in a screen you do the same.

Here's an example. I'm going to use a screen I made ages ago instead of typing out a new one for you:

Code: Select all

screen about():

    tag menu
    style_prefix "about"
    add gui.screens_menu_background
    
    vbox:
        add gui.menu_about_text
        xalign 0.5
        ypos 25

    vbox:
        
        xpos gui.screens_xpos
        ypos gui.screens_ypos

        label "[config.name!t]"
        if build.a:
            text _("Version [config.version!t]ɑ\n")
        else:
            text _("Version [config.version!t]β\n")
            
        text _("Made with {a=https://www.renpy.org/}Ren'Py{/a} [renpy.version_only].\n\n[renpy.license!t]\n")
        text _("Feedback can be left at the {a=https://lemmasoft.renai.us/forums/viewtopic.php?f=43&t=43580}Lemma Soft forums{/a}.\n")

        text _("This [disclaimer!t]\n")
        text _("[disclaimer_pt2!t]\n")
        text _("[disclaimer_pt3!t]")
            
    use navi


style about_vbox:
    xmaximum 680
    
style about_label_text:
    size gui.label_text_size
    color gui.credit_menu_text_color

style about_text:
    size gui.credit_menu_text_size
    color gui.credit_menu_text_color

Then in my options file, I have:

Code: Select all

define config.name = _("Cooking with RWBY")
define gui.show_name = False
define config.version = "0.05"
define build.name = "CookingwithRWBY"
define build.a = True

define imp = "Imperf3kt"
define special_t = _("Monreak 'Monty' Oum - RWBY creator and director\nTom 'PyTom' Rothamel - developer of Ren'Py\nThe wonderful users at Lemma Soft forums\nThe team at RoosterTeeth animation")
define montyquote = _("\"I believe that the human spirit is indomitable.\nIf you endeavor to achieve, it will happen given enough resolve.\nIt may not be immediate, and often your greater dream is something you will not achieve in your own lifetime.\nThe effort you put forth to anything transcends yourself, for there is no futility even in death.\"")
define disclaimer = _("program is not endorsed by Rooster Teeth in any way. Content in this product, including views, opinions and thoughts are those of Imperf3kt.")
define disclaimer_pt2 = _("Furthermore, anybody is hereby given permission to edit, modify or otherwise use this product and the parts that comprise this product, without needing to obtain the approval of, nor give credit to the original developer, provided you follow the terms of the licenses associated with this product as well as the Rooster Teeth {a=http://roosterteeth.com/about/faq/content-usage-guidelines/}content usage guidelines{/a}.")
define disclaimer_pt3 = _("Rooster Teeth and RWBY are trade names or registered trademarks of Rooster Teeth Productions, LLC.\n© Rooster Teeth Productions, LLC.")
Now let's imagine I want to change my disclaimer based on a variable (pretend player reaches halfway and sets variable $ halfway == True)
I can use a conditional for that.

Code: Select all

    if halfway:
        text _("This game pirated by\n")
        text _("Some dude.\n")
    else:
        text _("This [disclaimer!t]\n")
        text _("[disclaimer_pt2!t]\n")
        text _("[disclaimer_pt3!t]")
Last edited by Imperf3kt on Thu Jun 22, 2017 6:43 pm, edited 1 time in total.
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
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Display text on custom screen

#3 Post by TellerFarsight »

Nothing as complicated as that. I essentially just want another piece of dialogue to be shown in a large viewport with some other knicks and knacks for decoration.

Code: Select all

screen email_display():
    style_prefix "email_display"
    frame:
        area (10, 60, 200, 480)
        viewport:
            scrollbars "vertical"
            mousewheel True
            draggable True
            vbox:
                # and then I don't know what to put here

label start:
    "A long time ago in a galaxy far far away"
    show screen email_display("800 years of trade agreements")  # I don't know how to do this line in a way that I can just put some dialogue in here. I want to be able to use this screen repeatedly throughout the game, and the only thing that changes is the text in the viewport
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: Display text on custom screen

#4 Post by Imperf3kt »

Apply the same logic:

Code: Select all

define "email_1" = "800 years of trade agreements"

screen email_display():
    style_prefix "email_display"
    frame:
        area (10, 60, 200, 480)
        viewport:
            scrollbars "vertical"
            mousewheel True
            draggable True
            vbox:
                if email == 1:
                    text "[email_1]"


default email = 0

label start:
    "A long time ago in a galaxy far far away"
    $ email += 1
    show screen email_display
I suggest putting all your emails in a separate .rpy as you may end up with a lot.
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
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Display text on custom screen

#5 Post by TellerFarsight »

Code: Select all

# That's gonna be a very long...

            vbox:
                if email == 1:
                    text "[email_1]"
                if email == 2:
                    text "[email_2]"
                if email == 3:
                    text "[email_3]"
                if email == 4:
                    text "[email_4]"
                if email == 5:
                    text "[email_5]"
                if email == 6:
                    text "[email_6]"
                if email == 7:
                    text "[email_7]"

# and so on... won't it?
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Display text on custom screen

#6 Post by TellerFarsight »

Code: Select all

# Can I just

define ekk = "Bleh!"

vbox:
    text _("[ekk]")
I'd like to just display the ones I specify, and not have it dependent on keeping track of the numbers like that.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

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

Re: Display text on custom screen

#7 Post by Imperf3kt »

No, because how do you change the text?
That would work in the dialogue box, but not in a screen.

You don't need to use my numbers variable example exactly as is, but you do need some way to change what text is displayed, otherwise it'll display all of it.

This, is assuming I've understood your intentions correctly.
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
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Display text on custom screen

#8 Post by trooper6 »

TellerFarsight wrote:Nothing as complicated as that. I essentially just want another piece of dialogue to be shown in a large viewport with some other knicks and knacks for decoration.

Code: Select all

screen email_display():
    style_prefix "email_display"
    frame:
        area (10, 60, 200, 480)
        viewport:
            scrollbars "vertical"
            mousewheel True
            draggable True
            vbox:
                # and then I don't know what to put here

label start:
    "A long time ago in a galaxy far far away"
    show screen email_display("800 years of trade agreements")  # I don't know how to do this line in a way that I can just put some dialogue in here. I want to be able to use this screen repeatedly throughout the game, and the only thing that changes is the text in the viewport
You almost had it.

If you look at the documentation on screens, you note that it can take parameters. https://www.renpy.org/doc/html/screens. ... -statement

So in the definition of your screen, you note that you'll be passing some text to the screen (text we will call "email"). Then when you call the screen, make sure you pass in the text.

It looks like this:

Code: Select all

screen email_display(email):
    style_prefix "email_display"
    frame:
        area (10, 60, 200, 480)
        viewport:
            scrollbars "vertical"
            mousewheel True
            draggable True
            vbox:
                text '[email]'

label start:
    "A long time ago in a galaxy far far away"
    show screen email_display("800 years of trade agreements") 
Because screens take parameters, you can pass in most anything: text, lists, numbers, variables, class objects, images. You just have to "catch" that data in the definition.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

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

Re: Display text on custom screen

#9 Post by Imperf3kt »

/me learns a new function today
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
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: Display text on custom screen

#10 Post by TellerFarsight »

Okay, I knew it had to be something simple like that.
I was trying
text ["email"] and it didn't work. I didn't realize the quotation marks had to go on the outside.

Now, how can I get this email screen to function similar to dialogue.
Right now, the "email" screen is unresponsive, because it's a viewport I guess; I need to click outside of it to move on to the next bit of dialogue. How do I make it so that it does that?
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

Post Reply

Who is online

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