I was doing some testing today and I've decided I wanted to add some kind of chat system to my game.
- I've edited this post to show my solution to this! -
I've managed to fix this problem and I guess I'll post my full code here just in case anyone else needed it~
Code: Select all
#---CHAT SYSTEM
init -1 python:
class Message(object):
def __init__(self, pic, name, message):
self.pic = pic
self.name = name
self.message = message
# Mom chatlog:
class MChatlog(object):
def __init__(self):
self.history = []
def addmessage(self, pic, name, message):
self.history.append(Message(pic, name, message))
def delchat(self):
self.history = []
screen chatdisplay:
tag menu
use no_quick_menu
zorder 5
add "gui/nvl.png"
viewport:
mousewheel True
side_area (430, 120, 400, 400)
yinitial 0.0
scrollbars "vertical"
vbox:
spacing 10
for i in Mchat.history:
if i.name == "You": #check speakers name
frame:
xalign 1.0
#position the player's chat bubble
xoffset 75
background "#dedede"
maximum (300, 500)#(300,200)
vbox:
hbox:
add i.pic xalign 1.0
text i.name font "fonts/Satisfy-Regular.ttf" size 25 color "#dedede" outlines [(1, "#595959")] xalign 1.0
text i.message font "fonts/ABeeZee-Regular.ttf" size 18 color "#ffffff" xalign 1.0
else:
frame:
xalign 0.0
background "#595959"
maximum (300, 500)
vbox:
hbox:
add i.pic
text i.name font "fonts/Satisfy-Regular.ttf" size 25 color "#dedede" outlines [(1, "#595959")]
text i.message font "fonts/ABeeZee-Regular.ttf" size 18 color "#ffffff"
init:
default Mchat = MChatlog()
#define avatars
image mom = "messenger/av/Mom_s.png"
#image mrj = "messenger/av/Mom_s.png" --> need image
image you = "messenger/av/You_s.png"
image alice = "messenger/av/Alice_s.png"
image tahiel = "messenger/av/Tahiel_s.png"
image wren = "messenger/av/Wren_s.png"
image kevan = "messenger/av/Kevan_s.png"
image nieves = "messenger/av/Nieves_s.png"
#----------------------------------------
label chat_test:
n "okay, let me add some messages..."
$ Mchat.addmessage('you', "You", "Mom, I'll be home later today.")
#$metxt=True
play sound "audio/message.ogg"
show screen chatdisplay
$renpy.pause()
$ Mchat.addmessage('you', "You", "I'm on my way to a Friends Place.")
#$metxt=True
play sound "audio/message.ogg"
$renpy.pause()
$ Mchat.addmessage('mom', "Mom", "That's alright honey. Just don't go home too late.")
#$metxt=False
play sound "audio/message.ogg"
$renpy.pause()
$ Mchat.addmessage('mom', "Mom", "Okay?")
#$metxt=False
play sound "audio/message.ogg"
$renpy.pause()
$ Mchat.addmessage('you', "You", "Yeah, yeah. I know.")
#$metxt=True
play sound "audio/message.ogg"
$renpy.pause()
$ Mchat.addmessage('mom', "Mom", "Alright, I'll be waiting..")
#$metxt=False
play sound "audio/message.ogg"
$renpy.pause()
$ Mchat.addmessage('mom', "Mom", "Love you {image=kiss}")
#$metxt=False
play sound "audio/message.ogg"
$renpy.pause()
$ Mchat.addmessage('you', "You", "{image=kiss} {image=kiss}")
#$metxt=True
play sound "audio/message.ogg"
$renpy.pause()
hide screen chatdisplay
n "There. It works now!"
So what did I change?
* The user could not click to advance text - Apparently I had my screen defined with the 'Modal=True' statement and 'renpy.pause()' was not having any effect. Deleting this statement seemed to have fixed this issue.
* I've added a way to check if speakers name is set to 'You' so that the chat bubble is positioned and aligned to the right.
---
Thank you for reading and have a nice day~ n.n