Listing the contents of inventories/message inboxes
Posted: Thu Apr 07, 2011 1:04 pm
Hello, all! I've been trying to create a message system using The Inventory and Money System in the cookbook as my base. I'm aware there is an actual message system also in the cookbook, but as it isn't documented I can't understand what does what and I am loath to copy+paste code into my project without knowing exactly how it works (I'm trying to teach myself here!).
So far I have this as the contents of scripts I've named messages.rpy:
In script.rpy, at certain points in the story the messages 'welcome1' and 'welcome2' are inserted into inbox.messages. Using the inbox.has_message() function I'm able to confirm if a particular message has been inserted successfully.
What I'd like to know is how I'd go about listing the subjects all the messages in inbox.messages, and placing each entry within its own ui.textbutton which I can use to call up a new frame containing the message in full. Basically, making an actual inbox.
I'm brand new to python, so attempts to hack together a function for reading from inbox.message and displaying the list aren't going so well. I figured I should stop guessing and ask for a bit of help!
So far I have this as the contents of scripts I've named messages.rpy:
Code: Select all
init python:
#Message classes
class Message:
def __init__(self, subject, sender, body):
self.subject = subject
self.sender = sender
self.body = body
class Inbox:
def __init__(self):
self.messages = []
def send(self, message):
self.messages.append(message)
return True
def has_message(self, message):
if message in self.messages:
return True
else:
return False
#Variable declaration
inbox = Inbox()
messages = Inbox
#The messages themselves
welcome1 = Message("Welcome to the message system!", "Eileen", "Welcome to the message system! This is where you can send and receive messages from others.")
welcome2 = Message("Using the message system", "Eileen", "Using the message system is a snap! Simply select the message you want to read in your inbox with a click and it opens! But you knew that already, didn't you?")What I'd like to know is how I'd go about listing the subjects all the messages in inbox.messages, and placing each entry within its own ui.textbutton which I can use to call up a new frame containing the message in full. Basically, making an actual inbox.
I'm brand new to python, so attempts to hack together a function for reading from inbox.message and displaying the list aren't going so well. I figured I should stop guessing and ask for a bit of help!