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: 594
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 » Sat Mar 02, 2019 1:06 am

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 » Fri May 17, 2019 6:12 am

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.

Post Reply

Who is online

Users browsing this forum: No registered users