Basic Message System

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Message
Author
User avatar
wyverngem
Miko-Class Veteran
Posts: 615
Joined: Mon Oct 03, 2011 7:27 pm
Completed: Simple as Snow, Lady Luck's Due,
Projects: Aether Skies, Of the Waterfall
Tumblr: casting-dreams
itch: castingdreams
Location: USA
Contact:

Re: Basic Message System

#91 Post by wyverngem »

MRF wrote: Wed Feb 27, 2019 2:55 am is there a way to check if an email can be reply ?

Code: Select all

        if current_message and current_message.reply_label:
            textbutton "Reply" action current_message.reply
        else:
            textbutton "Reply" action None
This if statement checks if there's a reply_label in current_message. It says if the current_message value is not None and the current.message.reply_label isn't none either. Then create a button called Reply. current_message was defined earlier in the screen with a for loop that said look at all the items in the list mail. If the item is viewable and not read then make a button. You can add if i.reply_label within the for loop to only create buttons for items within mail that have a reply_label. You could create a function that looks for one too if you want to get more advance. I'd search for the subject and then reply_label because you don't know the reply_label if you're searching for it.

ysa27
Newbie
Posts: 5
Joined: Thu Jan 10, 2019 9:28 pm
Deviantart: ysa27
Contact:

Re: Basic Message System

#92 Post by ysa27 »

saguaro wrote: Fri Feb 08, 2013 5:12 pm This is a basic in-game message system that uses screens and a little Python. It tracks the read status of messages and includes "mark all read", delete, and restore functions. It also has reply and draft features that use Ren'Py's built-in menus.

Updates:
05/20/14 v 1.2
- Added a simple draft feature that allows player to send messages to names on a contact list (same setup as replies)
- Incorporated message delay based on xavimat's contributions
- Refactored code and put updated choice screen in messages.rpy

screenshot0005.png screenshot0006.png

Include the following after your start label:

Code: Select all

label start:
    $ mail = []
    $ mail_queue = [] # for message delay
    $ contacts = []  # for draft feature
The syntax for adding messages is add_message(subject line, sender name, message body). Include these anywhere in the script after the mail list is defined.

Code: Select all

    $ add_message("Welcome to Ren'Py!", "Eileen", "This is a test message.")
    $ add_message("Delayed message test", "Eileen", "This is a delayed message.", delay=True)
Delayed messages can be delivered like so:

Code: Select all

    $ deliver_next() 
    $ deliver_all()
Check to see if messages have been read based on the message title:

Code: Select all

    if check("TPS Reports"):
        e "Yep!"
    else:
        e "Nope!" 
If a message is reply-able, the syntax will be add_message(subject line, sender name, message body, reply_label).

Code: Select all

    $ add_message("I'm so mad!", "Fred", "You were mean to me.  You better apologize!", "fred_reply")
You will need to create the reply label. The template is:

Code: Select all

label fred_reply(current_message):
    menu:
        "I won't apologize, Fred. You smell like old socks and I hate you!":
            # whatever happens
            $ current_message.can_reply = False
        "You're right. I'm sorry, Fred.  Let's be friends.":
            # whatever happens
            $ current_message.can_reply = False
        "Don't reply yet.":
            pass
    return
The player can "draft messages" to people on a contact list. To add people to the list:

Code: Select all

    $ fredo = Contact("Fred", "fred_draft")

    # to change the draft message, do something like 
    $ fredo.draft = "fred_draft2"
    # if you don't want Fred on the list anymore (sorry Fred)
    $ fredo.delete() 
The template for drafts is:

Code: Select all

label fred_draft(contact, message_title="Listen, Fred..."):
    menu:
        "You're my very best friend! Let's get tacos!":
            $ contact.draft_label = None # must include this line for each option 
            $ add_message("Taco Time", "Fred", "Yay tacos!!!")   
        "I don't think we should be friends anymore.":
            $ contact.draft_label = None
            $ add_message(":(", "Fred", "WHYYYYYYYYYYYY")            
        "Discard draft.":
            pass
    return
Additional Features:
* Adding a sound effect when messages are received - by xavimat
* Adding time delay to replies - by xavimat

messages.rpy contains everything you need, including the modified choice screen. script.rpy has a demo. Drop all three scripts into a new project to test it out.
Is there a way to change just the frame of the background to an image? Just the frame to an image.

Dart87
Newbie
Posts: 9
Joined: Mon Dec 02, 2013 12:26 pm
Contact:

Re: Basic Message System

#93 Post by Dart87 »

Hi !

I know it's an old post, but I'm in need for some help.

I'm trying to add saguaro message system in a 'computer like' imagebutton screen. It should be easy but I'v some issues.

I have a background image for my computer desktop. The player can click on a "Mail" button. And saguaro message system appear (the Inbox). For now it's just fine.

But when I want to draft a new message, or reply to one, I can't see the reply or draft 'screens'. And I know why, it's because the background image is on a superior layer than saguaro message system.
So, ok, I'm trying to fix this by moving saguaro message system on another layer. I'v managed to move the 'contact' screen in the layer that I want.

Code: Select all

screen mailbox_commands:
    hbox:
        if available_drafts:
            textbutton "New Draft" action Show("contacts", _layer="scrmenu2") ######## HERE


Who's calling this on:

Code: Select all

screen contacts:
    modal True
    frame:
        style_group "mailbox"
        xsize 200
        vbox:
            label "Contacts"
            for name in contacts:
                if name.draft_label:
                    textbutton name.name action [name.draft, Hide("contacts")] ###### HERE


Who's calling (I think):

Code: Select all

class Contact(store.object):
        def __init__(self, name, draft_label):
            self.name = name
            self.draft_label = draft_label
            self.add_contact()

        def add_contact(self):
            contacts.append(self)

        def draft(self):
            global draft_screen
            draft_screen = True
            renpy.call_in_new_context(self.draft_label,contact=self)  ###### HERE
            draft_screen = False
And that's my problem, I don't know how to send this "renpy.call_in_new_context..." in a layer.


I don't know if I was clear. But if someone know how to fix this, it will be a great help !


Oh, and I've fixed this:
LyannaCore wrote: Wed Jun 21, 2017 2:03 pm I realize this systems is a bit old now, so it's probably just something that has changed with Renpy updates, but trying to use it messes up my existing menus.

With the messages.rpy included and integrated as required, they are aligned to the left and have no change when moused over:

The #updated choice screen of the script replace the choice screen of Ren'py. So I'v juste changed the values of #updated choice screen to be the same of my version of Ren'py.

Like this:

Code: Select all

# updated choice screen
screen choice:

    if reply_screen or draft_screen:
        # this is the menu for message replies and drafts
        frame:
            style_group "mailbox"

            vbox:
                label "Ecrire"
                if reply_screen:
                    text ("To: " + current_message.sender)
                    text ("Subject: Re: " + current_message.subject)
                else:
                    text ("To: " + contact.name)
                    text ("Subject: " + message_title)
                null  height 30

                for caption, action, chosen in items:

                    if action:
                        button:#boutton choix réponse
                            action action
                            style "choice_button" xalign 0.5 

                            text caption text_align 0.5

                    else:
                        text caption style "menu_caption"

    else:
        # this is the default choice menu
        window:
            style "choice" ####################### # PREVIOUSLY "menu_widow"
            xalign 0.5
            yalign 0.5

            vbox:
                style "menu"
                xalign 0.5 ####################### # ADDED THIS VALUES
                yalign 0.5 
                yanchor 0.5 
                spacing gui.choice_spacing ####################### # PREVIOUSLY "spacing 2"

                for caption, action, chosen in items:

                    if action:

                        button:
                            action action
                            style "choice_button" xalign 0.5 ####################### # PREVIOUSLY "menu_choice_button"

                            text caption style "menu_choice" xalign 0.5  

                    else:
                        text caption style "menu_caption" xalign 0.5

With those modifications, it will fix your problem.

User avatar
Kokoro Hane
Eileen-Class Veteran
Posts: 1236
Joined: Thu Oct 27, 2011 6:51 pm
Completed: 30 Kilowatt Hours Left, The Only One Girl { First Quarter }, An Encounter ~In The Rain~, A Piece of Sweetness, Since When Did I Have a Combat Butler?!, Piece by Piece, +many more
Projects: Fateful Encounter, Operation: Magic Hero
Organization: Tofu Sheets Visual
Deviantart: kokoro-hane
itch: tofu-sheets-visual
Contact:

Re: Basic Message System

#94 Post by Kokoro Hane »

I'm curious if anyone knows how to make it where you see your reply just like reading the other messages? So when you hit "Reply" and have choices, after you've selected your choice, you will see your entire e-mail and have to click a "Send" button to finalize it.

For example:

I get a message from Eileen that says "Hi!"
When I press reply, you get a set of options. One is "Hello" and the other is "Go Away"
If I select "Hello", I will see a full on message "Hello there. How are you?" and instead of reply at the bottom it's "Send".
If I select "Go Away", same thing I will see a full on message but "Go away, I don't like you!" and again "Send" is in place of the reply button since I am the one replying

I've seen something like this done before, but can't figure out how to do it. (I am using a version of Ren'Py that handles legacy code for this project).
PROJECTS:
Operation: Magic Hero [WiP]
Piece By Piece [COMPLETE][Spooktober VN '20]
RE/COUNT RE:VERSE [COMPLETE][RPG]
Since When Did I Have a Combat Butler?! [COMPLETE][NaNoRenO2020+]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]

But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"

Post Reply

Who is online

Users browsing this forum: No registered users