Page 1 of 1

Thoughts on condensing chat bubble code (Closed~)

Posted: Wed Aug 12, 2020 12:16 am
by Geckos
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


Re: Thoughts on condensing chat bubble code

Posted: Wed Aug 12, 2020 2:18 am
by philat
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.

Re: Thoughts on condensing chat bubble code

Posted: Wed Aug 12, 2020 3:15 pm
by Remix
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.

Re: Thoughts on condensing chat bubble code

Posted: Thu Aug 13, 2020 3:24 am
by Geckos
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

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

Posted: Thu Aug 13, 2020 11:17 am
by Remix
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)