Basic Message System
Posted: 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
Include the following after your start label:
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.
Delayed messages can be delivered like so:
Check to see if messages have been read based on the message title:
If a message is reply-able, the syntax will be add_message(subject line, sender name, message body, reply_label).
You will need to create the reply label. The template is:
The player can "draft messages" to people on a contact list. To add people to the list:
The template for drafts is:
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.
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
Include the following after your start label:
Code: Select all
label start:
$ mail = []
$ mail_queue = [] # for message delay
$ contacts = [] # for draft feature
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)
Code: Select all
$ deliver_next()
$ deliver_all()
Code: Select all
if check("TPS Reports"):
e "Yep!"
else:
e "Nope!"
Code: Select all
$ add_message("I'm so mad!", "Fred", "You were mean to me. You better apologize!", "fred_reply")
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
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()
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
* 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.