telegram messenger (4 version)

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

Re: telegram messenger (2 version)

#61 Post by Nanahs »

Oh, ok. Got it. Thamk you! :)

But now how I show the image inside the message?

Because the messages are working this way, like the older code like:

Code: Select all

    python:    
        msg("Hello Anna!!", who=1)
But in the new code it's like this (image and sound):

Code: Select all

    $ msg (None, audio="opening", who=1)
    $ msg (None, pic="crow", who=1)

User avatar
sDextra
Regular
Posts: 40
Joined: Fri Oct 12, 2018 2:06 am
Organization: Event Horizon Games
Github: sDextra
Location: Kazakhstan
Contact:

Re: telegram messenger (2 version)

#62 Post by sDextra »

Nanahs wrote: Thu Jan 10, 2019 1:36 pm Oh, ok. Got it. Thamk you! :)

But now how I show the image inside the message?

Because the messages are working this way, like the older code like:

Code: Select all

    
    python:    
        msg("Hello Anna!!", who=1)
But in the new code it's like this (image and sound):

Code: Select all

    $ msg (None, audio="opening", who=1)
    $ msg (None, pic="crow", who=1)

Code: Select all

python:
    msg("Hello Anna!!", who=1)
==

Code: Select all

$ msg ("Hello Anna!!", who=1)
Just try it in your version:

Code: Select all

python:
    msg (None, pic='your_pic', who=1)
Path to the image: 'images/messenger/pic/*your_pic*.jpg'

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: telegram messenger (2 version)

#63 Post by Nanahs »

sDextra wrote: Thu Jan 10, 2019 1:48 pm
Nanahs wrote: Thu Jan 10, 2019 1:36 pm Oh, ok. Got it. Thamk you! :)

But now how I show the image inside the message?

Because the messages are working this way, like the older code like:

Code: Select all

    
    python:    
        msg("Hello Anna!!", who=1)
But in the new code it's like this (image and sound):

Code: Select all

    $ msg (None, audio="opening", who=1)
    $ msg (None, pic="crow", who=1)

Code: Select all

python:
    msg("Hello Anna!!", who=1)
==

Code: Select all

$ msg ("Hello Anna!!", who=1)
Just try it in your version:

Code: Select all

python:
    msg (None, pic='your_pic', who=1)
Path to the image: 'images/messenger/pic/*your_pic*.jpg'
Thank you! It worked with the image.

Only two things are not working.
I'm getting embarrassed from making so many questions. Sorry :oops: :oops: :lol:

The audio didn't work:

Code: Select all

    python:
        msg (None, audio="birds", who=1)
I got this error:

Code: Select all

    While running game code:
  File "game/script.rpy", line 487, in script
    python:
  File "game/script.rpy", line 488, in <module>
    msg (None, audio="birds", who=1)
TypeError: msg() got an unexpected keyword argument 'audio'
I have an "audio" folder and the "birds.mp3" inside it.

PS: I changed "audio" to "sound". The audio player shows up. But when I click to play, it keeps telling me it could find "birds" file even though it's there.

I also this. To make the message go "automatic", without the person clicking on the screen. I added "p" in "renpy.pause(p)".
It was really good, cause I could use "p=3" for short messages, "p=6" for biggers messages, etc. Control how long the other character was "typing" and then automatically send it.

So the message would be:

Code: Select all

    python:    
        msg("Hello Anna!", p=3, who=1)
And I did the same thing in this new code:

Code: Select all

    def msg(txt, who=False, sound=False, pic=False, hm=False):
        if message_time:
            h,m = message_time
            hm = hm if hm else '%s:%s'%(h,m)
            time_update()
        hm = get_current_time() if message_time_current else hm 

        store.m_msg.append((who, txt, sound, pic, hm))
        store.yadj.value = store.yadj.range+300
        renpy.restart_interaction()
        if who:
            renpy.play("new_message.mp3", "sound")
        renpy.pause(p)
But I keep getting the error "global name 'p' is not defined". Why is it not defined if I added it "renpy.pause(p)". It worked in the other code :?:

User avatar
sDextra
Regular
Posts: 40
Joined: Fri Oct 12, 2018 2:06 am
Organization: Event Horizon Games
Github: sDextra
Location: Kazakhstan
Contact:

Re: telegram messenger (2 version)

#64 Post by sDextra »

Nanahs wrote: Thu Jan 10, 2019 1:36 pm So the message would be:

Code: Select all

    python:    
        msg("Hello Anna!", p=3, who=1)
And I did the same thing in this new code:

Code: Select all

    def msg(txt, who=False, sound=False, pic=False, hm=False):
        if message_time:
            h,m = message_time
            hm = hm if hm else '%s:%s'%(h,m)
            time_update()
        hm = get_current_time() if message_time_current else hm 

        store.m_msg.append((who, txt, sound, pic, hm))
        store.yadj.value = store.yadj.range+300
        renpy.restart_interaction()
        if who:
            renpy.play("new_message.mp3", "sound")
        renpy.pause(p)
But I keep getting the error "global name 'p' is not defined". Why is it not defined if I added it "renpy.pause(p)". It worked in the other code :?:

You forgot about the keyword argument:

Code: Select all

def msg(txt, who=False, sound=False, pic=False, hm=False, p=1) ### 'p=default'

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: telegram messenger (2 version)

#65 Post by Nanahs »

sDextra wrote: Thu Jan 10, 2019 3:57 pm
Nanahs wrote: Thu Jan 10, 2019 1:36 pm So the message would be:

Code: Select all

    python:    
        msg("Hello Anna!", p=3, who=1)
And I did the same thing in this new code:

Code: Select all

    def msg(txt, who=False, sound=False, pic=False, hm=False):
        if message_time:
            h,m = message_time
            hm = hm if hm else '%s:%s'%(h,m)
            time_update()
        hm = get_current_time() if message_time_current else hm 

        store.m_msg.append((who, txt, sound, pic, hm))
        store.yadj.value = store.yadj.range+300
        renpy.restart_interaction()
        if who:
            renpy.play("new_message.mp3", "sound")
        renpy.pause(p)
But I keep getting the error "global name 'p' is not defined". Why is it not defined if I added it "renpy.pause(p)". It worked in the other code :?:

You forgot about the keyword argument:

Code: Select all

def msg(txt, who=False, sound=False, pic=False, hm=False, p=1) ### 'p=default'
Thank you so much :)

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: telegram messenger (2 version)

#66 Post by Nanahs »

Do you know what this error means?

Code: Select all

While running game code:
  File "game/script.rpy", line 456, in script
    python:
  File "game/script.rpy", line 457, in <module>
    msg (None, sound="opening.mp3", who=1)
TypeError: unsupported operand type(s) for -: 'ATLTransform' and 'float'
It shows up whenever I try to use any of those codes:

Code: Select all

    python:
        msg (None, sound="birds.mp3", who=1)


    python:
        msg (None, sound="birds", who=1)


    python:
        msg("", who=1, sound="birds.mp3")        


    python:
        msg (None, audio="birds.mp3", who=1)

User avatar
sDextra
Regular
Posts: 40
Joined: Fri Oct 12, 2018 2:06 am
Organization: Event Horizon Games
Github: sDextra
Location: Kazakhstan
Contact:

Re: telegram messenger (2 version)

#67 Post by sDextra »

Nanahs wrote: Fri Jan 11, 2019 2:39 pm Do you know what this error means?

Code: Select all

While running game code:
  File "game/script.rpy", line 456, in script
    python:
  File "game/script.rpy", line 457, in <module>
    msg (None, sound="opening.mp3", who=1)
TypeError: unsupported operand type(s) for -: 'ATLTransform' and 'float'
It shows up whenever I try to use any of those codes:

Code: Select all

    python:
        msg (None, sound="birds.mp3", who=1)


    python:
        msg (None, sound="birds", who=1)


    python:
        msg("", who=1, sound="birds.mp3")        


    python:
        msg (None, audio="birds.mp3", who=1)
I do not see this line: 'msg (None, sound="opening.mp3", who=1)'
Why there is both 'sound' and 'audio'. In the old version 'sound', in the new 'audio', they replace each other.

I do not have old version, so I can not say exactly what the problem is. :?:
Сan you send your project in PM? I will try to solve the problem.

User avatar
Nanahs
Veteran
Posts: 310
Joined: Wed Aug 22, 2018 5:50 pm
Contact:

Re: telegram messenger (2 version)

#68 Post by Nanahs »

sDextra wrote: Fri Jan 11, 2019 5:13 pm
Nanahs wrote: Fri Jan 11, 2019 2:39 pm Do you know what this error means?

Code: Select all

While running game code:
  File "game/script.rpy", line 456, in script
    python:
  File "game/script.rpy", line 457, in <module>
    msg (None, sound="opening.mp3", who=1)
TypeError: unsupported operand type(s) for -: 'ATLTransform' and 'float'
It shows up whenever I try to use any of those codes:

Code: Select all

    python:
        msg (None, sound="birds.mp3", who=1)


    python:
        msg (None, sound="birds", who=1)


    python:
        msg("", who=1, sound="birds.mp3")        


    python:
        msg (None, audio="birds.mp3", who=1)
I do not see this line: 'msg (None, sound="opening.mp3", who=1)'
Why there is both 'sound' and 'audio'. In the old version 'sound', in the new 'audio', they replace each other.

I do not have old version, so I can not say exactly what the problem is. :?:
Сan you send your project in PM? I will try to solve the problem.
Thank you so much! I sent you the project :)

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: telegram messenger (2 version)

#69 Post by nanashine »

Hello! Can I make just one more question? hahah :oops:

This is my audio channel:

Code: Select all

init python:
    renpy.music.register_channel("player", mixer='sfx', loop=False, stop_on_mute=True) 
And this is the messenger screen code:

Code: Select all

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 15 xsize 550 xalign 0.4 box_reverse True:
                    for message in m_msg[::-1]:
                        $ who, txt, sound, pic, hm = message
                        $ xgn = 0.0 if who else 1.0
                        $ xpic = 380
                        if sound:
                            hbox spacing -60 xalign xgn:
                                $ sound = 'sfx/%s.mp3'%(sound)
                                imagebutton auto "messenger/sound_%s.png" xalign xgn action Play("player", sound)
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'
                        elif pic:
                            hbox spacing -60 xalign xgn:
                                button xalign xgn xmaximum 580 xpadding 4 top_padding 30 bottom_padding 40 background 'box' hover_background 'h_box':
                                    action Show('full_pic', pic=pic)
                                    add "messenger/pic/%s.jpg"%(pic) size (380, 600)
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'
                        else: 
                            hbox spacing -60 xalign xgn:
                                button xalign xgn xmaximum 580 xpadding 20 top_padding 10 bottom_padding 30 background 'box':
                                    text "%s"%(txt) style "txt_base"
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'

        # Bar
        vbar value YScrollValue("vp_msg") style "bar_vert"
~

When I click to play the audio it works normally. But when I click again, the audio doesn't stop playing.
It plays the audio again, instead of being a "play/stop" button.
Is there a way I can change it in this code?
I created a separate button to do it, but it's not practical at all.

Thanks.
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
sDextra
Regular
Posts: 40
Joined: Fri Oct 12, 2018 2:06 am
Organization: Event Horizon Games
Github: sDextra
Location: Kazakhstan
Contact:

Re: telegram messenger (2 version)

#70 Post by sDextra »

nanashine wrote: Fri May 03, 2019 4:52 pm Hello! Can I make just one more question? hahah :oops:

This is my audio channel:

Code: Select all

init python:
    renpy.music.register_channel("player", mixer='sfx', loop=False, stop_on_mute=True) 
And this is the messenger screen code:

Code: Select all

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 15 xsize 550 xalign 0.4 box_reverse True:
                    for message in m_msg[::-1]:
                        $ who, txt, sound, pic, hm = message
                        $ xgn = 0.0 if who else 1.0
                        $ xpic = 380
                        if sound:
                            hbox spacing -60 xalign xgn:
                                $ sound = 'sfx/%s.mp3'%(sound)
                                imagebutton auto "messenger/sound_%s.png" xalign xgn action Play("player", sound)
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'
                        elif pic:
                            hbox spacing -60 xalign xgn:
                                button xalign xgn xmaximum 580 xpadding 4 top_padding 30 bottom_padding 40 background 'box' hover_background 'h_box':
                                    action Show('full_pic', pic=pic)
                                    add "messenger/pic/%s.jpg"%(pic) size (380, 600)
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'
                        else: 
                            hbox spacing -60 xalign xgn:
                                button xalign xgn xmaximum 580 xpadding 20 top_padding 10 bottom_padding 30 background 'box':
                                    text "%s"%(txt) style "txt_base"
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'

        # Bar
        vbar value YScrollValue("vp_msg") style "bar_vert"
~

When I click to play the audio it works normally. But when I click again, the audio doesn't stop playing.
It plays the audio again, instead of being a "play/stop" button.
Is there a way I can change it in this code?
I created a separate button to do it, but it's not practical at all.

Thanks.
Hmm, you can try something like that

Code: Select all

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 15 xsize 550 xalign 0.4 box_reverse True:
                    for message in m_msg[::-1]:
                        $ who, txt, sound, pic, hm = message
                        $ xgn = 0.0 if who else 1.0
                        $ xpic = 380
                        if sound:
                            $ sound = 'sfx/%s.mp3'%(sound)
                            $ playing = renpy.music.get_playing(channel='player')
                            $ now_play = sound == playing
                            hbox spacing -60 xalign xgn:
                                imagebutton auto "messenger/sound_%s.png" xalign xgn action If(now_play, [Stop('player')], [Play('player', sound)]):
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'
                        elif pic:
                            hbox spacing -60 xalign xgn:
                                button xalign xgn xmaximum 580 xpadding 4 top_padding 30 bottom_padding 40 background 'box' hover_background 'h_box':
                                    action Show('full_pic', pic=pic)
                                    add "messenger/pic/%s.jpg"%(pic) size (380, 600)
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'
                        else: 
                            hbox spacing -60 xalign xgn:
                                button xalign xgn xmaximum 580 xpadding 20 top_padding 10 bottom_padding 30 background 'box':
                                    text "%s"%(txt) style "txt_base"
                                if hm:
                                    text "{t}%s{/t}"%(hm) style 'txt_time'

        # Bar
        vbar value YScrollValue("vp_msg") style "bar_vert"

nanashine
Regular
Posts: 129
Joined: Thu Nov 30, 2017 1:44 pm
itch: renpytom
Contact:

Re: telegram messenger (2 version)

#71 Post by nanashine »

Thank you so much sDextra! It worked :)
I can't access my other account cause I don't remember the e-mail I used *cries in emoji*.

User avatar
Godline
Veteran
Posts: 499
Joined: Fri Jun 27, 2014 12:26 am
Completed: numerous
Tumblr: godlinegames
Deviantart: godline-games
itch: godline
Contact:

Re: telegram messenger (2 version)

#72 Post by Godline »

Hey sDextra!
Used this code in our LDjam game: https://ldjam.com/events/ludum-dare/44/ ... of-romance

(credited)
Thanks so much! <3

fauxbius
Newbie
Posts: 5
Joined: Fri Jun 14, 2019 5:56 pm
Contact:

Re: telegram messenger (2 version)

#73 Post by fauxbius »

This code is amazing, thanks!

Quick questions:

Is it possible to stop the script progressing until the name input has been completed?

Once I've put in the name, does it have to display as a text? I'd prefer to input the name, then on a new line put "Oh hi, [name]" instead of just having the name on it's own

Is it possible to show clickable playable videos?

User avatar
sDextra
Regular
Posts: 40
Joined: Fri Oct 12, 2018 2:06 am
Organization: Event Horizon Games
Github: sDextra
Location: Kazakhstan
Contact:

Re: telegram messenger (2 version)

#74 Post by sDextra »

fauxbius wrote: Mon Jun 24, 2019 9:15 am Is it possible to stop the script progressing until the name input has been completed?
If I understand you correctly, you can try using this function:

Code: Select all

$ freeze() 
# your actions
$ unfreeze()
fauxbius wrote: Mon Jun 24, 2019 9:15 am Once I've put in the name, does it have to display as a text? I'd prefer to input the name, then on a new line put "Oh hi, [name]" instead of just having the name on it's own
This is already implemented in the code.
Image

fauxbius wrote: Mon Jun 24, 2019 9:15 am Is it possible to show clickable playable videos?
I think it is possible, but it will take some time.

fauxbius
Newbie
Posts: 5
Joined: Fri Jun 14, 2019 5:56 pm
Contact:

Re: telegram messenger (2 version)

#75 Post by fauxbius »

sDextra wrote: Mon Jun 24, 2019 10:38 am
If I understand you correctly, you can try using this function:

Code: Select all

$ freeze() 
# your actions
$ unfreeze()
I actually ended up doing the below using the del_last_msg, as the freeze didn't work, it wouldn't unfreeze after taking a name, or wouldn't let me inout anything. The problem is that you type the name, it gets sent and displayed as a message. You can't use the input and just display the last line in this code without using del_last_msg to clear the previous one first.

Code: Select all

    $ msg(None, name_input=True)    
    if name=="Jack":
            $ msg ("Yeah, this is Jack")
    else:
        $ del_last_msg()
        $ msg ("No, it\'s [name]")
sDextra wrote: Mon Jun 24, 2019 10:38 am I think it is possible, but it will take some time.
Thanks for the help!

Post Reply

Who is online

Users browsing this forum: No registered users