Help understanding how this imagebutton works?

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
User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Help understanding how this imagebutton works?

#1 Post by Nanahs »

I'm using the first messenger: viewtopic.php?f=51&t=50153

My doubt is how the sound imagebutton inside the message works.

This is the messenger code (older version):

Code: Select all

init python:
    ### Цветовая схема
    style_button_back = "#282E33" 
    style_button_hovr = "#5F6C77"
    style_button_inst = "#14171A"


    # Стиль кнопок
    style.btn = Style(style.default)
    style.btn.background = style_button_back
    style.btn.hover_background = style_button_hovr
    style.btn.insensitive_background = style_button_inst
    # Стиль ползунка
    style.bar_vert = Style(style.default)
    style.bar_vert.right_bar = style_button_inst 
    style.bar_vert.left_bar = style_button_inst 
    style.bar_vert.thumb = style_button_hovr
    style.bar_vert.bar_vertical = True
    style.bar_vert.bar_invert = True
    style.bar_vert.xalign = 1.0
    style.bar_vert.yalign = 0.8
    style.bar_vert.xsize = 20
    style.bar_vert.ysize = 530
    # Стиль текста
    style.txt_base = Style(style.default)
    style.txt_base.font = "gui/tahoma.ttf"
    style.txt_base.xalign = 0.5
    style.txt_base.yalign = 0.5
    style.txt_base.size = 30
    style.txt_base.color = "#fff"

    yadj = ui.adjustment()
    # Добавление нового сообщения
    def msg(txt, who=False, sound=False, p=None):  
        store.m_msg.append((who, txt, sound))
        store.yadj.value = store.yadj.range+300
        renpy.restart_interaction()
        if who:
            renpy.play("new_message.mp3", "sound")
        renpy.pause(p)
    # Удаление последнего сообщения
    def del_last_msg():
        if len(store.m_msg) > 0:
            del store.m_msg[-1]
    # Удаление всех сообщений
    def del_all_msg():
        store.m_msg = []
        

# Экран сообщения
screen telegram():
    frame background "messenger/back.png" xysize (700,975) align (0.9,.5):
        frame background None xysize (560, 810) align (0.5,0.58):
            viewport id "vp_msg" mousewheel True  yadjustment yadj:
                vbox spacing 8 xsize 550 xalign 0.4 box_reverse True:
                    for message in m_msg[::-1]: 
                        $ who, txt, sound = message
                        $ xgn = 0.0 if who else 1.0
                        if sound:
                            imagebutton auto "messenger/sound_%s.png" xalign xgn action Play("sound", sound)
                        else: 
                            button xalign xgn xmaximum 700 xpadding 20 ypadding 10 background Frame("messenger/box.png", 25, 25):
                                text "%s"%(txt) style "txt_base"
                

        # Стрелка
        imagebutton auto "messenger/arr_%s.png" xalign 100 ypos -0.05 action MainMenu(confirm=True)
        # Ползунок прокрутки
        vbar value YScrollValue("vp_msg") style "bar_vert"
This is how you use it on scrip:

Code: Select all

label start:
    scene black with dissolve
    show screen telegram

    python:
        msg("Hey what happened yesterday?", who=True)
        msg("Too many things. I'll send you an audio.")
        msg("", who=1, sound="sound_message.mp3")
And that's what it looks like:
Image

The problem is that I have 5 different characters, and I wanted each one of them to have a customized audio box.
Like this for example (I'd make 5 different versions, using their avatars):

Image

I tried to make more than 1 "who". I tried to add the sound "sound="sound_message.mp3" inside of a normal "msg" after an "{image=jhon}". I tried creating another screen for another character but it didn't work either (maybe I didn't edit the codes properly?) I tried many things. But nothing worked.
I got confused because I've never seen a imagebutton being used inside of a textbox or anything like that. So I couldn't figure out how to solve it.

Does anyone have any idea on how it works? And if I can stablish different sound boxes?

I was going to ask that on the messenger thread, but I though I would end up making it look confusing there.

Thanks.

Post Reply

Who is online

Users browsing this forum: No registered users