Creating a texting function for a phone 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
kedta35
Regular
Posts: 45
Joined: Wed Aug 30, 2023 1:31 pm
Contact:

Creating a texting function for a phone screen

#1 Post by kedta35 »

I want to add a texting function to a phone I made in Ren'Py. The texts will be predetermined so I'm fine with using images for the texts and actually, I would prefer it so I that images could be sent. The main functions that I really want to know how to implement are:
  • For the texts to go up when either an optional text is clicked or the phone screen is clicked.
  • Making the texts go up automatically to make room for new texts when the texts fill the phone screen
I know that a frame should be used for scrolling and that a for loop is most likely how to implement this but I can't understand how I'm not sure how.

For now, the above functions are what I'm mainly trying to find out but if anyone can help with these also, that would be great:
  • Having all the messages can be accessible through an "app" on the phone screen
  • Keeping all messages with any characters be viewable at any point by scrolling up and the messages not just being deleted after a scene/event.
Thanks for reading, please help.

User avatar
m_from_space
Miko-Class Veteran
Posts: 981
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Creating a texting function for a phone screen

#2 Post by m_from_space »

kedta35 wrote: Tue Apr 16, 2024 8:15 pm I want to add a texting function to a phone I made in Ren'Py.
I don't know how much experience in programming in Python and Renpy you have, but saving messages can be achieved very easily inside a list. Each message on the other hand could be also a list or a tuple, that contains a name, the text and maye a timestamp if that is what you want. But since you want your messages to be images (which I strongly advice against), you can also just save images inside the list. You could also create classes and functions and whatnot, but let's stick to the basics if you're new.

Simple example using two lists to store the message data:

Code: Select all

# messages not yet shown to the player
default messages_queue = [
    ("Eileen", "Hello, I am Eileen."),
    ("Eileen", "What's up?")
    ]
# all messages that have ever been shown
default messages_history = []
I know that a frame should be used for scrolling (...)
No, you have to use a viewport for that. This is not HTML, frames have different meaning here.
Making the texts go up automatically to make room for new texts when the texts fill the phone screen
A typical method for making auto-scrolling text inside a viewport is using an y-adjustment object:

Code: Select all

screen phone_messages():
    default yadj = ui.adjustment()
    # make autoscroll possible
    if yadj.value == yadj.range:
        yadj.value = float('inf')
    viewport:
        yadjustment yadj
        # insert your messages here
        for message in messages_history:
            text message
For the texts to go up when either an optional text is clicked or the phone screen is clicked.
Just make "yadj" a global variable (in the example it's a screen variable) and set it to float('inf') whenever you want the text to scroll to the bottom.
Having all the messages can be accessible through an "app" on the phone screen
Create a button that then shows the messages screen using the Show() function.
Keeping all messages with any characters be viewable at any point by scrolling up and the messages not just being deleted after a scene/event.
Does this mean you want your Renpy dialogue to be the messages you are going to show? Because in that case, it's getting a bit complicated. But it's possible and there are good demos out there. If your game is not only a phone I advice against it, because you would need to alter the say screen.

kedta35
Regular
Posts: 45
Joined: Wed Aug 30, 2023 1:31 pm
Contact:

Re: Creating a texting function for a phone screen

#3 Post by kedta35 »

Thanks, I took this and applied some more that I found and got this:

Code: Select all

default messages_queue = [
    ("Eileen 1.png"),
    ("Eileen 2.png"),
    ("Eileen 1.png"),
    ("Eileen 2.png"),
    ("Eileen 1.png"),
    ("Eileen 2.png"),
    ("Eileen 1.png"),
    ("Eileen 2.png"),
    ("Eileen 1.png"),
    ("img3.png"),
    ]

default messages_history = []

screen phone_messages():
    python:
        yadjValue = float("inf")
        yadj = ui.adjustment()
        yadj.value = yadjValue

    style_prefix "phoneFrame"
    frame at phone_transform(phone_position_x, phone_position_y):
        frame style_prefix None:
            background None xysize(490,697)
            ypos .04
            viewport yadjustment yadj:
                draggable True
                mousewheel True
                vbox:
                    for message in messages_history:
                        imagebutton:
                            idle message
                            if message == "img3.png":
                                action Jump("start")
                        
                        
init python:
    def add_message(text):
        messages_queue.append((text))

label phone_jump:

    python:
        while messages_queue:
            text = messages_queue.pop(0)
            messages_history.append(f"{text}")

    call screen phone_messages
This seems to work almost exactly how I want it to but the only issue is that all the messages show instantly rather than one by one as the phone/screen is clicked.

User avatar
m_from_space
Miko-Class Veteran
Posts: 981
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Creating a texting function for a phone screen

#4 Post by m_from_space »

kedta35 wrote: Wed Apr 17, 2024 8:04 am

Code: Select all

label phone_jump:

    python:
        while messages_queue:
            text = messages_queue.pop(0)
            messages_history.append(f"{text}")

    call screen phone_messages
This seems to work almost exactly how I want it to but the only issue is that all the messages show instantly rather than one by one as the phone/screen is clicked.
In this code snippet you remove all messages from the queue and add them to the history. So of course all messages will show at the same time. You should only add one message at a time with each click.

Post Reply

Who is online

Users browsing this forum: No registered users