Thoughts on condensing chat bubble code (Closed~)

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
Geckos
Veteran
Posts: 471
Joined: Fri Aug 17, 2012 8:33 am
Completed: Brilliant Shadows, Perceptions of the Dead, The Phantom Icecream Truck
Projects: Embers of Magic, Pale Spectrum, Perceptions of the Dead
Organization: Ithaqua Labs
Tumblr: geckosart
Deviantart: sitaart
Contact:

Thoughts on condensing chat bubble code (Closed~)

#1 Post by Geckos » Wed Aug 12, 2020 12:16 am

I use this code to make speech bubbles on the screen for my characters, which I manually place with $jill_talk=1.
1 is far left, 6 is far right. The 7-12 are the same positions, just larger chat bubbles for when the characters have a lot to say.

I've been staring at this code for awhile, and I feel like there's got to be a cleaner way to squash all of this info, as it's the same coordinates that I use throughout the entire game to display the chat box.

As it is right now, I copy/paste these two blocks of code for each new character that I define, and I just change the name. I.e. Jill_talk becomes Dave_talk (so I can have their bubbles appear in different locations, not a universal one.)

I was just curious if anyone had any thoughts on the matter!
And in trade for picking your brain, I'd be happy to offer a quick portrait sketch of one of your characters or a character from media that you like~ (/bribes with art/) XD

Code: Select all

init:
    $jill_talk=1

screen say(who, what):
        #zorder 2
 
# Defaults for side_image and two_window
        default side_image = None
## ■██▓▒░ Jill bubble░▒▓█████████████████████████████████████■
        
        elif (who=="Jill"):
            if (jill_talk==1):
                add "sprites/bubble_1.png" xpos 180 ypos 400 at boxpop
            elif (jill_talk==2):
                add "sprites/bubble_1.png" xpos 380 ypos 400 at boxpop
            elif (jill_talk==3):
                add "sprites/bubble_1.png" xpos 580 ypos 400 at boxpop
            elif (jill_talk==4):
                add "sprites/bubble_1.png" xpos 780 ypos 400 at boxpop
            elif (jill_talk==5):
                add "sprites/bubble_1.png" xpos 980 ypos 400 at boxpop
            elif (jill_talk==6):
                add "sprites/bubble_1.png" xpos 1180 ypos 400 at boxpop
                
            elif (jill_talk==7):
                add "sprites/bubble_1B.png" xpos 180 ypos 400 at boxpop
            elif (jill_talk==8):
                add "sprites/bubble_1B.png" xpos 380 ypos 400 at boxpop
            elif (jill_talk==9):
                add "sprites/bubble_1B.png" xpos 580 ypos 400 at boxpop
            elif (jill_talk==10):
                add "sprites/bubble_1B.png" xpos 780 ypos 400 at boxpop
            elif (jill_talk==11):
                add "sprites/bubble_1B.png" xpos 980 ypos 400 at boxpop
            elif (jill_talk==12):
                add "sprites/bubble_1B.png" xpos 1180 ypos 400 at boxpop

#██████████████████████████████████████████████████████████████████████████■
## ■██▓▒░ Jill who/what░▒▓█████████████████████████████████████■                
                elif (who=="Jill"):
                    if (jill_talk==1):
                        text who id "who" xpos 465 ypos 410
                        $whoOutside=who
                    elif (jill_talk==2):
                        text who id "who" xpos 665 ypos 410
                        $whoOutside=who
                    elif (jill_talk==3):
                        text who id "who" xpos 865 ypos 410
                        $whoOutside=who
                    elif (jill_talk==4):
                        text who id "who" xpos 1065 ypos 410
                        $whoOutside=who
                    elif (jill_talk==5):
                        text who id "who" xpos 1265 ypos 410
                        $whoOutside=who
                    elif (jill_talk==6):
                        text who id "who" xpos 1465 ypos 410
                        $whoOutside=who
                        
                    elif (jill_talk==7):
                        text who id "who" xpos 465 ypos 410
                        $whoOutside=who
                    elif (jill_talk==8):
                        text who id "who" xpos 665 ypos 410
                        $whoOutside=who
                    elif (jill_talk==9):
                        text who id "who" xpos 865 ypos 410
                        $whoOutside=who
                    elif (jill_talk==10):
                        text who id "who" xpos 1065 ypos 410
                        $whoOutside=who
                    elif (jill_talk==11):
                        text who id "who" xpos 1265 ypos 410
                        $whoOutside=who
                    elif (jill_talk==12):
                        text who id "who" xpos 14650 ypos 410
                        $whoOutside=who
                    
                    else:    
                        text who id "who" xpos 570 ypos 615
                    
                    if (jill_talk==1):
                        text what id "what" xpos 505 ypos 492 xmaximum 500
                    elif (jill_talk==2):
                        text what id "what" xpos 705 ypos 492 xmaximum 500
                    elif (jill_talk==3):
                        text what id "what" xpos 905 ypos 492 xmaximum 500
                    elif (jill_talk==4):
                        text what id "what" xpos 1105 ypos 492 xmaximum 500
                    elif (jill_talk==5):
                        text what id "what" xpos 1305 ypos 492 xmaximum 500
                    elif (jill_talk==6):
                        text what id "what" xpos 1505 ypos 492 xmaximum 500
                    
                    
                    elif (jill_talk==7):
                        text what id "what" xpos 505 ypos 535 xmaximum 500
                    elif (jill_talk==8):
                        text what id "what" xpos 705 ypos 535 xmaximum 500
                    elif (jill_talk==9):
                        text what id "what" xpos 905 ypos 535 xmaximum 500
                    elif (jill_talk==10):
                        text what id "what" xpos 1105 ypos 535 xmaximum 500
                    elif (jill_talk==11):
                        text what id "what" xpos 1305 ypos 535 xmaximum 500
                    elif (jill_talk==12):
                        text what id "what" xpos 1505 ypos 535 xmaximum 500
                    
                    
                    
                    else:    
                        text what id "what" xpos 505 ypos 470 xmaximum 500

Attachments
screenie_1.jpg
Last edited by Geckos on Thu Aug 13, 2020 3:25 am, edited 1 time in total.
Image ImageImage

philat
Eileen-Class Veteran
Posts: 1763
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Thoughts on condensing chat bubble code

#2 Post by philat » Wed Aug 12, 2020 2:18 am

I... would not do it this way in the first place. But I suppose the simplest way to cut down on some of this is using some math.

Code: Select all

add "sprites/bubble_1.png" xpos -20+(200*jill_talk) ypos 400 at boxpop # adjust numbers accordingly, I didn't look at it super hard.

User avatar
Remix
Eileen-Class Veteran
Posts: 1505
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Thoughts on condensing chat bubble code

#3 Post by Remix » Wed Aug 12, 2020 3:15 pm

I would be inclined to move to a system that uses expanding Frames to accommodate the text, then just worry about the position of the frame.

Though it likely doesn't fully suit your use-case, I feel you would benefit from examining the Speech Bubbles system on my GitHub.
If you read the Overview and bit about styling Frames, it might give you some ideas on ways to progress.
Frameworks & Scriptlets:

User avatar
Geckos
Veteran
Posts: 471
Joined: Fri Aug 17, 2012 8:33 am
Completed: Brilliant Shadows, Perceptions of the Dead, The Phantom Icecream Truck
Projects: Embers of Magic, Pale Spectrum, Perceptions of the Dead
Organization: Ithaqua Labs
Tumblr: geckosart
Deviantart: sitaart
Contact:

Re: Thoughts on condensing chat bubble code

#4 Post by Geckos » Thu Aug 13, 2020 3:24 am

philat wrote:
Wed Aug 12, 2020 2:18 am
I... would not do it this way in the first place. But I suppose the simplest way to cut down on some of this is using some math.

Code: Select all

add "sprites/bubble_1.png" xpos -20+(200*jill_talk) ypos 400 at boxpop # adjust numbers accordingly, I didn't look at it super hard.
I appreciate your thoughts, and taking any time to look!
Remix wrote:
Wed Aug 12, 2020 3:15 pm
I would be inclined to move to a system that uses expanding Frames to accommodate the text, then just worry about the position of the frame.

Though it likely doesn't fully suit your use-case, I feel you would benefit from examining the Speech Bubbles system on my GitHub.
If you read the Overview and bit about styling Frames, it might give you some ideas on ways to progress.
Hah so I spent the last 3 hours fiddling with that, and while I couldn't get the Thought bubbles to work, I think I Rather like the system! It's a lot more versatile than anything I've worked with before, thank you for sharing~ I am still totally down to do a portrait sketch for you, if that at all interests you XD
Attachments
speech_bubble_screenie_yeet_v1.jpg
Image ImageImage

User avatar
Remix
Eileen-Class Veteran
Posts: 1505
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Thoughts on condensing chat bubble code (Closed~)

#5 Post by Remix » Thu Aug 13, 2020 11:17 am

Thought bubbles are a lot trickier to do as you need to think a lot more about which bits stretch and which bits tile. The tile="integer" setting of Frames can help, though it still never looks quite perfect (and can cause banding on fine images). Best might be to draw one at each desired width and just stretch the waist part.

Glad you like it and found it useful.
No need on the sketch at the moment (will message you if I do need one some day)
Frameworks & Scriptlets:

Post Reply

Who is online

Users browsing this forum: Google [Bot], yayamiho