[Solved] I'm having trouble creating text messages

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
neriowl
Newbie
Posts: 2
Joined: Wed Jul 28, 2021 3:17 pm
Discord: Neriowl#2608
Contact:

[Solved] I'm having trouble creating text messages

#1 Post by neriowl »

Hello,
I want to display text messages that emulate a chat,
I want the messages to appear one by one, and I want them to be reviewed with a scroll bar ...

Something like that:
Image


This is the script I have, but I don't know how to put pauses between the messages ...

Code: Select all


screen viewport_example():
    side "c r":
         area (60, 150, 1150, 470)

         viewport id "vp":
             draggable True

             vbox:
                 spacing 10
                 xalign 0.5
                 yalign 0.8
                 frame:
                     background Solid("#00000070")
                     text "{color=#dea0b8}{b}PJ 1{/color}{/b}\nText1"
                 add "pic3.png"
                 frame:
                     background Solid("#00000070")
                     text "{color=#db9e7d}{b}PJ 2{/color}{/b} \nText 2"
                 frame:
                     background Solid("#00000070")
                     text "{color=#7db1db}{b}PJ 3{/color}{/b} \nText 3 text 3 text 3 \nText 3 text 3 text 3 text 3 text 3text 3 text 3 \nText 3 text 3 text 3\nText 3 text 3 text 3 text 3 text 3 \nText 3 text 3 text 3 text 3 text 3text 3 text 3 \nText 3 text 3 text 3\nText 3 text 3 text 3 text 3 text 3"
                 frame:
                     background Solid("#00000070")
                     text "{color=#db9e7d}{b}PJ 2{/color}{/b} \nText 4 text 4 text 4 \nText 4 text 4 text 4\ nText 4 text 4 text 4"
                 textbutton _("Reply") action Return()
         vbar value YScrollValue("vp")
# El juego comienza aquí.

label start:

    scene gui_cel2
    call screen viewport_example
    scene bg
    menu:
        "Reply1.-":
            jump fin
        "Reply2.-":
            jump fin

label fin:
    "End"

    return

I have seen other topics with message systems but
1. one message replaces another
2. the messages are displayed but they are lost as they do not have a scroll bar
And that's not what I'm looking for...

I don't know if I'm on the right track or if there is an easier way to do things, I would really appreciate any help you can give me.
Last edited by neriowl on Tue Aug 03, 2021 9:09 am, edited 1 time in total.

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

Re: I'm having trouble creating text messages

#2 Post by Alex »

neriowl wrote: Mon Aug 02, 2021 11:22 am ...I don't know if I'm on the right track or if there is an easier way to do things, I would really appreciate any help you can give me.
If you don't need fully-functional message system but just a visual effect, you could try to make it like:
- make a counter variable,
- add check for this variable before each message in your screen,
- then increase the value of variable (manually or using timer in your screen).

Code: Select all

default messages_counter = 0

screen viewport_example():
    side "c r":
        area (60, 150, 1150, 470)

        viewport id "vp":
            draggable True

            vbox:
                spacing 10
                xalign 0.5
                yalign 0.8

                $ if messages_counter > 0:
                    frame:
                        background Solid("#00000070")
                        text "{color=#dea0b8}{b}PJ 1{/color}{/b}\nText1"

                $ if messages_counter > 1:
                    add "pic3.png"
                    frame:
                        background Solid("#00000070")
                        text "{color=#db9e7d}{b}PJ 2{/color}{/b} \nText 2"

                $ if messages_counter > 2:
                    frame:
                        background Solid("#00000070")
                        text "{color=#7db1db}{b}PJ 3{/color}{/b} \nText 3 text 3 text 3 \nText 3 text 3 text 3 text 3 text 3text 3 text 3 \nText 3 text 3 text 3\nText 3 text 3 text 3 text 3 text 3 \nText 3 text 3 text 3 text 3 text 3text 3 text 3 \nText 3 text 3 text 3\nText 3 text 3 text 3 text 3 text 3"

                $ if messages_counter > 3:
                    frame:
                        background Solid("#00000070")
                        text "{color=#db9e7d}{b}PJ 2{/color}{/b} \nText 4 text 4 text 4 \nText 4 text 4 text 4\ nText 4 text 4 text 4"
                textbutton _("Reply") action Return()
        vbar value YScrollValue("vp")

But if you need more from this message system, then you need to store messages in a list and modify your screen to show messages from that list. So, later you could add new messages in a list.

Code: Select all

default messages_list = []

screen viewport_example():
    side "c r":
        area (60, 150, 1150, 470)

        viewport id "vp":
            draggable True

            vbox:
                spacing 10
                xalign 0.5
                yalign 0.8

                for message in messages_list:
                    frame:
                        background Solid("#00000070")
                        text "[message]"

                 textbutton _("Reply") action Return()
        vbar value YScrollValue("vp")

label start:
    scene gui_cel2
    show screen viewport_example
    $ renpy.pause(0.5)
    $ messages_list.append("{color=#dea0b8}{b}PJ 1{/color}{/b}\nText1")
    $ renpy.pause()
    $ messages_list.append("{color=#db9e7d}{b}PJ 2{/color}{/b} \nText 2")
    menu:
        "Choice 1":
            $ messages_list.append("{color=#dea0b8}{b}PJ 1{/color}{/b}\nAnswer1")
        "Choice 2":
            $ messages_list.append("{color=#dea0b8}{b}PJ 1{/color}{/b}\nAnswer2")
    "?!"

User avatar
neriowl
Newbie
Posts: 2
Joined: Wed Jul 28, 2021 3:17 pm
Discord: Neriowl#2608
Contact:

Re: I'm having trouble creating text messages

#3 Post by neriowl »

The second code it's just what I needed! Thanks a lot!!

Post Reply

Who is online

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