Marking in-game messages as either new or seen?

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
LittleUrchin
Regular
Posts: 43
Joined: Sat Aug 11, 2012 4:53 pm
Location: Trapped inside a snow cone with a purple walrus and a broken jukebox
Contact:

Marking in-game messages as either new or seen?

#1 Post by LittleUrchin »

So, I'm working on implementing a message system for my game where the characters send the player texts, and I'm using this code as the foundation. I plan on modifying the layout and stuff soon, but first I want to know if there's any way to mark messages as new or unseen at first, then upon clicking and opening it, it shows up as read/seen.

Of course I'll display this value with something like an exclamation point for new messages and check marks for read ones, but I'm stumped on how to add that to the code I linked to above.

Any help would be much appreciated!~

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Marking in-game messages as either new or seen?

#2 Post by saguaro »

I personally feel that screen language is the way to go for email systems because it is so easy to read. Please ask if you'd like to try that and don't know where to start.

But for this code, here's what I would do. Since each message is a tuple containing (subject, sender, message, condition), we already have a problem because tuples are immutable (can't change 'em). So I'd change the tuple to a list, which is mutable, and include a boolean to flag whether a message has been read or not. The first step would be to update the add_message function to automatically set the "read" status to false.

Code: Select all

    def add_message(subject, sender, message, condition=None, read=False):
        init_messages()
        store.messages.append( [subject, sender, message, condition, read] )
The next step is to modify the message display based on whether the message has been read or not. The show_messages_ui function is where your messages are iterated and displayed. You can use an if statement to show a different subject (with a !) if the message is new:

Code: Select all

        for message in store.messages:
            if (message[3] == None or eval(message[3]) == True):
                    styleIndex = "Message"
                    if (index == currentMessage):
                        styleIndex = "CurrentMessage"
                    ui.button(clicked=ui.returns(index),
                        style=style.messageButton[styleIndex])
                    if message[4]:
                        ui.text(message[0] + " - " + message[1], style=style.messageButtonText[styleIndex])
                    else:
                        ui.text(message[0] + " - " + message[1] + "!", style=style.messageButtonText[styleIndex])
            index = index + 1
Next we need to toggle that boolean when the user interacts by clicking the button. I guess we can update it when the message text pops up in the message viewport.

Code: Select all

        if (currentMessage >= 0) and (currentMessage < messageCount):
            hasMessage = True
            store.messages[currentMessage][4] = True
            ui.text(store.messages[currentMessage][2], style=style.messageText)
        else:
            hasMessage = False
            ui.null()
The ! will go away on the next interaction. In screen language we could add a SetValue action to the button and change the status when clicked, but I'm not sure how to do that with the older ui.button stuff. Maybe someone else can help.

LittleUrchin
Regular
Posts: 43
Joined: Sat Aug 11, 2012 4:53 pm
Location: Trapped inside a snow cone with a purple walrus and a broken jukebox
Contact:

Re: Marking in-game messages as either new or seen?

#3 Post by LittleUrchin »

Thanks for responding! I'll try adding that to my code for now.

I had attempted a couple weeks ago to make a new code based off of this one, but it failed pretty hard. I would love to make this message system with screen language instead if you or anyone else would be willing to help me. Otherwise, thanks for your help so far! ^^

I also want to be able to add a trash bin where the deleted messages go just in case the player changes their mind, along with the option to empty it, and a Reply button that opens up a small menu with a few optional responses for each unique message. I figure these are pretty hard/complicated to do, though, so their priority levels are lower than the first issue.

Again, thank you. I appreciate any help. ^^

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Marking in-game messages as either new or seen?

#4 Post by saguaro »

LittleUrchin wrote:I also want to be able to add a trash bin where the deleted messages go just in case the player changes their mind, along with the option to empty it, and a Reply button that opens up a small menu with a few optional responses for each unique message. I figure these are pretty hard/complicated to do, though, so their priority levels are lower than the first issue.
The first one can use the same basic idea, you could create a boolean for whether the message is deleted or not (maybe modify the existing spam filter feature if you aren't going to use it). Currently, the delete button actually removes the message from the list when clicked, which is not what you want. This would need to be updated to toggle the delete boolean instead.

The trash bin would be a separate screen that only displays messages with delete=True. I guess clicking the button would set delete=False (restore the message) and clicking a different button would actually remove them all from the list. For simplicity, message restoration may be all that is required.

Reply buttons can get as complex as you want, but a basic concept is to click a reply button that jumps to a label containing the responses you want, and once they have replied once they cannot jump to that label again. Hopefully that gives you some ideas to start with.

LittleUrchin
Regular
Posts: 43
Joined: Sat Aug 11, 2012 4:53 pm
Location: Trapped inside a snow cone with a purple walrus and a broken jukebox
Contact:

Re: Marking in-game messages as either new or seen?

#5 Post by LittleUrchin »

Ah, thank you sooo much! I'm trying to incorporate those things into a new code. I did keep the part of the code that comes after the styles since I'm including a large amount of possible messages and that appears to be the simplest way to organize them. (Even if I don't fully grasp how it works...) It's a work in progress, but hopefully I'll be able to get it functioning the way I want it to. ^^

The most difficult part seems to be the responses. I'm trying to figure out how to simplify the process, but I don't think I'll be able to avoid having to create branches upon branches of variables for all of the possible responses..

Anyway, I really appreciate all the help you've given me with this so far.~ ^^

User avatar
Foreign Taka
Newbie
Posts: 4
Joined: Sun Nov 03, 2013 11:25 am
Contact:

Re: Marking in-game messages as either new or seen?

#6 Post by Foreign Taka »

I know that this is an old post but it's the closest I've come across to what I'm thinking. Hope no-one minds!

I've noticed that you were discussing about general emails being read / unread. Is there an easy(ish) way to flag whether a specific email has been read, in advance of a follow-up action?

Something along the lines of: If X e-mail has been read then e-mail1_read=1

Hope this makes sense to peeps. Thanks!

User avatar
saguaro
Miko-Class Veteran
Posts: 560
Joined: Sun Feb 12, 2012 9:17 am
Completed: Locked-In, Sunrise, The Censor
Organization: Lucky Special Games
itch: saguarofoo
Location: USA
Contact:

Re: Marking in-game messages as either new or seen?

#7 Post by saguaro »

well in this example our messages are list items that look like: [subject, sender, message, condition, read]

so you could check based on the subject IF the message subject is a unique string, but you need to iterate since messages is a nested list. something like

Code: Select all

def check(subject):
    for item in messages:
        if item[0] == subject:
            if item[4]:
                return True

Post Reply

Who is online

Users browsing this forum: Lacha