[Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

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.
Post Reply
Message
Author
User avatar
nonlogical_coder
Newbie
Posts: 6
Joined: Sun Oct 18, 2020 12:06 pm
Organization: Nonlogical Coder
itch: nonlogicalcoder
Contact:

[Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#1 Post by nonlogical_coder » Sun Oct 18, 2020 2:16 pm

Demo Video:
Youtube: https://youtu.be/GAfO_lYWkzU

Possible Look and Feel if Implemented Properly:
2020-10-18_23-34-51.mp4_snapshot_01.37.208.jpg
2020-10-18_23-34-51.mp4_snapshot_00.55.032.jpg
2020-10-18_23-34-51.mp4_snapshot_00.10.337.jpg
Description:
This is a still-in-progress simple messaging system that I made.

Implemented Features:
​Messenger Version 1.0.0 [2020-10-20 - 12:02 AM]
  • One-to-One Text Messaging.
  • One-to-Many Text Messaging (Group Chats).
  • Typing Indicator.
  • Seen Feature for the Messenger's User.
  • Auto scrolling to bottom on each message entry.
  • Message Timestamps.
Planned Features:
  • Image/Displayable/Attachment Messaging.
  • Integrate with an overall Smartphone System that can contain other applications besides from this.
  • More...
Quickstart:
  • Download the file from my itch page (Consider supporting me if you like it :) Every help will go into the future development of the project as well as for my studies.)
  • Move/Copy the file to your Ren'Py game's folder, so it should look like as <Your Game Name>/game/messenger.rpy. Be noted that you can place it inside sub-folders, as long as those sub-folders are still inside the game directory.
  • Anywhere in your rpy files, we will declare the necessary instances of classes that are essential for the Messaging System, after all this extension is Object-Oriented so expect that every component is based on instanstation.

    Code: Select all

    ## Your characters for your game.
    define m = Character("Mike")
    define k = Character("Kaela")
    define j = Character("John")
    define v = Character("Vanessa")
    define s = Character("Shiela")
    
    ## Using the MessengerUser class, we create a new user that can be plugged in
    ## into our Messenger Application. We are using the characters that we defined
    ## earlier as the starting name of the users.
    default mc = MessengerUser(str(m))
    default kc = MessengerUser(str(k))
    default jc = MessengerUser(str(j))
    default vc = MessengerUser(str(v))
    default sc = MessengerUser(str(s))
    
    ## Using the MessengerConversation class, we create conversations that can be
    ## plugged into our Messenger Application. We are using the MessengerUser instances
    ## that we created earlier in specifying the participants for the conversations.
    ## If the name is set to None, then we will let the application to set the name base
    ## on the participants' names. By default, it is set to None, so you can directly ignore it.
    default c1 = MessengerConversation(
        name=None,
        participants=[
            kc, jc, vc, sc # 4 participants
        ],
    )
    
    default c2 = MessengerConversation(
        participants=[
            kc # 1 participant
        ],
    )
    
    ## Finally, we create our main Messenger Application using the Messenger class.
    
    ## We will specify who owns the Messenger App, by using the owner parameter
    ## and specifying the name of the variable of the MessengerUser.
    
    ## Through the participants parameter, we can restrict who are the available
    ## available messenger users that can access the Messenger application.
    
    ## This means that even if we specified a user in the conversation above,
    ## but we didn't specify that user as part of all the possible participants in general for all conversations,
    ## then that user won't be able to message through the application still.
    
    ## The conversations parameter, tell what are the pre-existing conversations that are already
    ## included in the app.
    default messenger = Messenger(
        owner=mc,
        participants=[
            kc, jc, vc, sc
        ],
        conversations=[
            c1
        ]
    )
    
  • Next is to create a screen that will use the messenger instance as the basis of operations.

    Code: Select all

    screen messenger(messenger):
    
        frame:
            background "#20202033"
            align (0.5, 0.5)
            xysize (300, 450)
    
            vbox:
                if not messenger.selected_conversation: # first we check if there's a conversation opened. if not then we will list all the conversations that can be opened. this serves as our home screen for the app.
                    for conversation in messenger.conversations:
                        textbutton conversation.name: # conversation.name, is what you specified earlier when we are creating the instances of conversations.
                            action messenger.SelectConversation(conversation) # messenger has an action SelectConversation, that can take a conversation instance, so we can select/open it.
    
                            background "#151515"
                            xysize (300, 30)
    
                else:
                    # this serves as our conversation screen, where we will list all the text messages.
                    $ conversation = messenger.selected_conversation # since this is else, this means that there is an opened conversation, so we alias it for much easier reference.
    
                    textbutton "Back": # a simple back button that can deselect all conversations using the messenger app's DeselectAllConversations action
                        action messenger.DeselectAllConversations()
    
                    viewport: # the viewport, we will give it an id so we can reference it in the auto-scroll function of the app.
                        id "vp"
                        scrollbars "vertical"
                        mousewheel True
    
                        vbox:
                            spacing 5
    
                            for message in conversation.messages: # conversation has a property called messages, where we can access all the messages added to the conversation, we will just loop in this list.
                                python:
                                    if message.is_from_owner: # we will define some variables to for the positioning of the text messages depending on the sender, if it is from sender then it should be right aligned and has green background.
                                        xalign = 1.0
                                        background = "#0f0"
    
                                    else:
                                        xalign = 0.0
                                        background = "#151515"
    
                                frame:
                                    xfill True
    
                                    frame:
                                        xmaximum 200 # we give the text box an xmaximum so we can see the positioning properly
                                        xalign xalign # the xalign that we defined earlier
                                        background background # the background we defined earlier
    
                                        vbox:
                                            text message.sender.name # the message has a property sender, which returns the MessageUser who sent the message, a MessageUser instance has a property name, we specified the name earlier using MessengerUser(str(m))
                                            text message.message # the message instance has a message property that returns the string message
                    
                    if conversation.typing_participants: # this is the typing indicator, we will first check if there are typing participants in the conversation.
                        text conversation.typing_message # after checking, we will use the property of the conversation typing_message to get the typing users information.
    
        if messenger.selected_conversation: # this is the auto scroll function, we will first check if there's a selected_conversation or opened conversation. if there is then we can auto-scroll down the viewport.
            add messenger.selected_conversation.AutoScrollDown(screen="messenger", id="vp", duration=2.0) # we will use the selected_conversation's AutoScrollDown displayable using the add statement of renpy, then specifying the current screen of the viewport and it's id. Optionally, we can specify the duration of the scroll, by default it is set to 0.25 second.
    
  • Now the last process is to use the screen anywhere in your script, by showing it and passing our main messenger instance, then add any messages or timestamps that you want inside a label.

    Code: Select all

    label start:
        show screen messenger(messenger) # we will show first the screen, and pass the messenger instance, in this way, we can create multiple messenger instances if needed or use different screens for different layout.
        
        ## we will go full python below, so we will start our statements with $.
        $ messenger.setTimestamp("October 2, 2020") # we will first set the timestamp  using the setTimestamp method of messenger before adding the message, so from this point messages will be marked with this timestamp, until the next set of timestamp.
        $ c1.messageText(mc, "Happy Birthday to me!!!") # we can now add messages, using the messageText function of the conversation that we want to fill with messages, we will pass the MessageUser instance, then the text message for that user. in this case, we are using the mc MessageUser instance that we declared earlier.
        
        $ messenger.setTimestamp("October 3, 2020") # new timestamp, meaning messages from this point will be under this timestamp.
        $ c1.messageText(kc, "OMG! It's your birthday today? I mean yesterday?") # new text, from different participant of the conversation.
    
        $ c1.messageText(kc, "I totally forgot about it!")
    
        $ c1.messageText(kc, "Sorry I wasn't able to prepare a gift for you today :(")
    
        $ c1.messageText(mc, "No sweat! I'm used to it already. Really.")
        
        $ c1.messageText(kc, "I--I'm sorry.")
        
        $ c1.messageText(jc, "F**king A!")
        $ c1.messageText(jc, "It's your birthday today?")
        $ c1.messageText(jc, "Holy s**t!")
        $ c1.messageText(jc, "I feel like I am a s**t friend now!")
        
        ## by default, the auto typing indicator function is true by default, but we can disable it
        ## by setting the typing_pause to None. setting it to a number will show the typing indicator until that amount
        ## of pause it met. setting it to "auto" is the same as the default, meaning it is calculated automatically,
        ## depending on the length of the characters in the message.
        ## the typing_hard is a boolean (true/false), if set to True then the game is pause until the typing_pause is met.
        ## basically, imagine the typing_pause and typing_hard as what you would normally do using the renpy.pause()
        $ c1.messageText(jc, "Where are you now bro? I'm coming for you. I'll try to grab the quickest possible gift that I can give.", typing_pause=3.0, typing_hard=True)
    
        $ c1.messageText(mc, "Don't bother, it's already midnight guys.")
        $ c1.messageText(mc, "I don't want to waste your time for this nonsense event.")
        $ c1.messageText(mc, "Don't worry I'll manage.")
        $ c1.messageText(mc, "Besides, this is not the first time that I've dealt with this kind of situation, so no worries :)")
    
        m "F**kers. So much for so-called friends. F**k you guys!" # this just shows the flexibility of the app, we can combine messaging as well as normal dialogue
        window hide
    
        $ c1.messageText(kc, "...", pause=0) # setting the pause or hard parameter means that the game will automatically proceed onto the statement below this after the seconds stated in the pause parameter, in this case, it's zero, so it will immediately show the jc text message after kc message.
        $ c1.messageText(jc, "...")
    
        pause
    
Tips, Tricks and Additional Reading:
To be filled out later. Sorry for the inconvenience. It's already past midnight in here :(. I'm gonna try to fill this out immediately once my schedule is free :).

About:
This is made by the Nonlogical Coder, under no license. My only illegit condition is to credit me, by including the Nonlogical Coder as part of your credits :)
Consider supporting the Nonlogical Coder if you are pleased with the project :).
Last edited by nonlogical_coder on Mon Oct 26, 2020 8:43 am, edited 3 times in total.

User avatar
parttimestorier
Veteran
Posts: 389
Joined: Thu Feb 09, 2017 10:29 pm
Completed: No Other Medicine, Well Met By Moonlight, RE:BURN, The Light at the End of the Ocean, Take A Hike!
itch: janetitor
Location: Canada
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#2 Post by parttimestorier » Mon Oct 19, 2020 8:56 am

Thanks for sharing your code! I'd like to get this file from your itch.io page and see whatever other information you might have there, since I'm always interested in checking out different ways of simulating instant messaging in RenPy. But when I clicked on your link to nonlogicalcoder.itch.io/messenger, I just got a 404 from itch.io.
ImageImageImage

User avatar
nonlogical_coder
Newbie
Posts: 6
Joined: Sun Oct 18, 2020 12:06 pm
Organization: Nonlogical Coder
itch: nonlogicalcoder
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#3 Post by nonlogical_coder » Mon Oct 19, 2020 1:25 pm

My bad! I forgot to publish it publicly. Sorry. It should be working by now :)

User avatar
gamerbum
Regular
Posts: 128
Joined: Fri Sep 18, 2015 4:40 pm
Projects: Our Lovely Escape, Mizari Loves Company
Organization: Reine Works
Tumblr: reineworks
Location: Canada
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#4 Post by gamerbum » Wed Oct 21, 2020 11:19 am

While this is super interesting and I'd love to check it out, there seems to be something missing from your installation instructions. I would recommend providing a full Ren'Py project folder to download as an example.

Anyway, here's the error it throws if you attempt to use the messenger on a fully fresh project:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 64, in script call
    $ c1.messageText(mc, "Happy Birthday to me!!!") # we can now add messages, using the messageText function of the conversation that we want to fill with messages, we will pass the MessageUser instance, then the text message for that user. in this case, we are using the mc MessageUser instance that we declared earlier.
  File "game/messenger.rpy", line 702, in script
    python:
  File "game/messenger.rpy", line 715, in <module>
    type_pause = len(message) * messenger_auto_typing_pause_per_character
NameError: name 'messenger_auto_typing_pause_per_character' is not defined

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 64, in script call
    $ c1.messageText(mc, "Happy Birthday to me!!!") # we can now add messages, using the messageText function of the conversation that we want to fill with messages, we will pass the MessageUser instance, then the text message for that user. in this case, we are using the mc MessageUser instance that we declared earlier.
  File "game/messenger.rpy", line 702, in script
    python:
  File "D:\RenPy\renpy-7.3.2-sdk\renpy\ast.py", line 914, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "D:\RenPy\renpy-7.3.2-sdk\renpy\python.py", line 2028, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/messenger.rpy", line 715, in <module>
    type_pause = len(message) * messenger_auto_typing_pause_per_character
NameError: name 'messenger_auto_typing_pause_per_character' is not defined

Windows-8-6.2.9200
Ren'Py 7.3.5.606
test 1.0
Wed Oct 21 12:15:49 2020

User avatar
nonlogical_coder
Newbie
Posts: 6
Joined: Sun Oct 18, 2020 12:06 pm
Organization: Nonlogical Coder
itch: nonlogicalcoder
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#5 Post by nonlogical_coder » Sat Oct 24, 2020 6:31 am

Thanks for reporting, I totally forgot about that variable, i just reuploaded quickly the fixed source code. I will try to provide more examples and a working sample project if possible, but right now I'm on a tight schedule because of my thesis, so possibly it won't happen sooner. But I'll try to provide the other details ASAP. And also, as stated in my planned features section, I might migrate this project into a Smartphone project that I've been planning, so it is possible that the next update of this messenger app would be included in that new project. Thanks for checking out :).

User avatar
gamerbum
Regular
Posts: 128
Joined: Fri Sep 18, 2015 4:40 pm
Projects: Our Lovely Escape, Mizari Loves Company
Organization: Reine Works
Tumblr: reineworks
Location: Canada
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#6 Post by gamerbum » Sun Oct 25, 2020 9:44 pm

nonlogical_coder wrote:
Sat Oct 24, 2020 6:31 am
Thanks for reporting, I totally forgot about that variable, i just reuploaded quickly the fixed source code. I will try to provide more examples and a working sample project if possible, but right now I'm on a tight schedule because of my thesis, so possibly it won't happen sooner. But I'll try to provide the other details ASAP. And also, as stated in my planned features section, I might migrate this project into a Smartphone project that I've been planning, so it is possible that the next update of this messenger app would be included in that new project. Thanks for checking out :).
Awesome work! I got it working, and this thing is great.

I did find one error in "screen messenger", but it's an easy fix. Autoscroll won't work with the example code because there's a small typo.

The following is the incorrect line.

Code: Select all

add messenger.selected_conversation.AutoScrollDown(screen="messenger2", id="vp", duration=2.0)
And here is the fix that allows the game to auto-scroll with the example code.

Code: Select all

add messenger.selected_conversation.AutoScrollDown(screen="messenger", id="vp", duration=2.0)]

KingPrinceGames
Newbie
Posts: 2
Joined: Mon Oct 26, 2020 6:45 pm
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#7 Post by KingPrinceGames » Mon Oct 26, 2020 6:53 pm

I think something went wrong:
Capture1.GIF
Getting This
and this...
Capture2.GIF
...and this.
I messed around with the frame size and textbutton sizes, but I still didn't achieve the desired effect of your original example. Open to suggestions.

P.S. Good luck with your forum spam!

User avatar
gamerbum
Regular
Posts: 128
Joined: Fri Sep 18, 2015 4:40 pm
Projects: Our Lovely Escape, Mizari Loves Company
Organization: Reine Works
Tumblr: reineworks
Location: Canada
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#8 Post by gamerbum » Mon Oct 26, 2020 8:27 pm

KingPrinceGames wrote:
Mon Oct 26, 2020 6:53 pm
I think something went wrong:

Capture1.GIF

and this...

Capture2.GIF

I messed around with the frame size and textbutton sizes, but I still didn't achieve the desired effect of your original example. Open to suggestions.

P.S. Good luck with your forum spam!
Gonna chime in since I had this issue as well, but it's just because we're using the new GUI set. You have to go into gui.renpy and remove the borders/adjust the font size.

KingPrinceGames
Newbie
Posts: 2
Joined: Mon Oct 26, 2020 6:45 pm
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#9 Post by KingPrinceGames » Mon Oct 26, 2020 10:27 pm

gamerbum wrote:
Mon Oct 26, 2020 8:27 pm
KingPrinceGames wrote:
Mon Oct 26, 2020 6:53 pm
I think something went wrong:

Capture1.GIF

and this...

Capture2.GIF

I messed around with the frame size and textbutton sizes, but I still didn't achieve the desired effect of your original example. Open to suggestions.

P.S. Good luck with your forum spam!
Gonna chime in since I had this issue as well, but it's just because we're using the new GUI set. You have to go into gui.renpy and remove the borders/adjust the font size.
You are awesome! I'm new-ish to Renpy so I don't have much experience with the old GUI set, thanks for pointing me in the right direction!

User avatar
Morhighan
Miko-Class Veteran
Posts: 959
Joined: Sun Jun 27, 2010 12:54 pm
Completed: AIdol, When Our Journey Ends, Forgotten Not Lost
Organization: MysteryCorgi
Tumblr: MysteryCorgi
Deviantart: MysteryCorgi
Soundcloud: MysteryCorgi
itch: MysteryCorgi
Location: USA
Contact:

Re: [Nonlogical Coder][In-Progress] Messenger - Version 1.0.0

#10 Post by Morhighan » Wed Oct 28, 2020 6:31 am

Thank you for sharing this, I'm excited to try it out.

Post Reply

Who is online

Users browsing this forum: XT9K