Why Isn't This Array-Based SMS System Working Properly?

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
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

Why Isn't This Array-Based SMS System Working Properly?

#1 Post by Braydxne »

I'm trying to make it so if a NEW message is added to the dialog, it will fade in, otherwise it doesn't. However all dialog just pops up with no animation at all.

Screens.rpy

Code: Select all

for message in messages2:
                if message[1] in oldmessages:
                    
                    if message[0] == "Marina":
                        frame:
                            background Solid("dddddd")
                            xpos 250
                            yoffset 5

                            vbox:
                                xsize 160
                                spacing 5
                                xalign 1
                                yalign 0

                                text "Me" size 26 color "#494949"
                                text message[1] size 24 color "#000000"

                    else:
                        frame:
                            background Solid("ebebeb")
                            xpos 5
                            yoffset 5

                            vbox:
                                xsize 160
                                spacing 5
                                xalign 0
                                yalign 0

                                text message[0] size 26 color "#494949"
                                text message[1] size 24 color "#000000"

                else:

                    if message[0] == "Marina":
                        frame at incoming_message:
                            background Solid("dddddd")
                            xpos 250
                            yoffset 5

                            vbox:
                                xsize 160
                                spacing 5
                                xalign 1
                                yalign 0

                                text "Me" size 26 color "#494949"
                                text message[1] size 24 color "#000000"

                    else:
                        frame at incoming_message:
                            background Solid("ebebeb")
                            xpos 5
                            yoffset 5

                            vbox:
                                xsize 160
                                spacing 5
                                xalign 0
                                yalign 0

                                text message[0] size 26 color "#494949"
                                text message[1] size 24 color "#000000"
Script.rpy

Code: Select all

init python:
    def addmsg(x):
        global messages
        global oldmessages
        messages.append(x)
        Hide("phonescr")()
        Show("phonescr",messages2=messages,oldmessages2=oldmessages)()
        oldmessages.append(x[1])
        
  	$ messages = [["Marina", "Die fatty"], ["Josh", "Die whale"],]
  	$ oldmessages = ["Die fatty", "Die whale"]
        
        $ addmsg(["Bianca","ur kidding right?? you know i wouldn't!! wtf!!"])
        
        
(I just omitted some parts that wouldn't interfere with this.)

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: Why Isn't This Array-Based SMS System Working Properly?

#2 Post by DannX »

This is only a guess, as I don't fully understand some parts of your code ($ statements inside addmsg() function? Does that work?) but it may have to do with your incoming_message transform, that I don't see here, maybe you need to link it to the text, instead of the frame, and maybe modify your code a little, again I'm not sure. Exactly how is this screen supposed to behave and how do you show it/call it in game?

User avatar
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

Re: Why Isn't This Array-Based SMS System Working Properly?

#3 Post by Braydxne »

DannX wrote: Mon Jun 18, 2018 1:17 pm This is only a guess, as I don't fully understand some parts of your code ($ statements inside addmsg() function? Does that work?) but it may have to do with your incoming_message transform, that I don't see here, maybe you need to link it to the text, instead of the frame, and maybe modify your code a little, again I'm not sure. Exactly how is this screen supposed to behave and how do you show it/call it in game?
The Script.rpy file has some other bits too, I just removed some parts. Here's the full script:

Code: Select all

init python:
    def addmsg(x):
        global messages
        global oldmessages
        messages.append(x)
        Hide("phonescr")()
        Show("phonescr",messages2=messages,oldmessages2=oldmessages)()
        oldmessages.append(x[1])

define e = Character("Eileen")

image phone = "images/Phone/PhoneBase.png"

transform phone_pickup:
    xpos 0.5 xanchor 0.5 yanchor 1.0 ypos 2.0
    easein 0.2 ypos 1.0

    on hide:
        easeout 0.2 ypos 2.0

transform scrolling_out_message:
    easeout 0.1 yoffset -30 alpha 0

transform incoming_message:
    yoffset 100
    alpha 0
    parallel:
        easein 0.1 alpha 1
    parallel:
        easein 0.2 yoffset 0

    on hide:
        scrolling_out_message
# The game starts here.

label start:

    $ messages = [["Marina", "Die fatty"], ["Josh", "Die whale"],]
    $ oldmessages = ["Die fatty", "Die whale"]
    scene bg room

    e "let me whip out my phone"
    show phone at phone_pickup
    $ renpy.pause(0.2)
    show screen phonescr(messages, oldmessages)
    $ renpy.pause(2)
    $ addmsg(["xxx","Ok?"])
    $ renpy.pause(2)
    $ addmsg(["Bianca","ur kidding right?? you know i wouldn't!! wtf!!"])
    $ renpy.pause(2)
    e "oh. alright."
    return

DannX
Regular
Posts: 99
Joined: Mon Mar 12, 2018 11:15 am
Contact:

Re: Why Isn't This Array-Based SMS System Working Properly?

#4 Post by DannX »

I think the problem might be the if/else statements in the screen.

The first if always is executed because message[1] is always in oldmessages from the start, so it always show the frame without animation, I think. It might be better if you define the variables as empty lists (arrays) first with default statement, and then fill them after the game starts and as the messages are shown. Maybe something like this:

Code: Select all

default messages = []
default oldmessages = []

label start:

    scene bg room

    e "let me whip out my phone"
    show phone at phone_pickup
    $ renpy.pause(0.2)
    $ messages = [["Marina", "Die fatty"], ["Josh", "Die whale"],]
    show screen phonescr(messages, oldmessages)
    $ oldmessages = ["Die fatty", "Die whale"]
    $ renpy.pause(2)
    $ addmsg(["xxx","Ok?"]) 
    $ renpy.pause(2)

User avatar
Braydxne
Regular
Posts: 50
Joined: Tue Aug 08, 2017 4:03 am
Projects: DR: Chains of Trust
Contact:

Re: Why Isn't This Array-Based SMS System Working Properly?

#5 Post by Braydxne »

DannX wrote: Mon Jun 18, 2018 2:51 pm I think the problem might be the if/else statements in the screen.

The first if always is executed because message[1] is always in oldmessages from the start, so it always show the frame without animation, I think. It might be better if you define the variables as empty lists (arrays) first with default statement, and then fill them after the game starts and as the messages are shown. Maybe something like this:

Code: Select all

default messages = []
default oldmessages = []

label start:

    scene bg room

    e "let me whip out my phone"
    show phone at phone_pickup
    $ renpy.pause(0.2)
    $ messages = [["Marina", "Die fatty"], ["Josh", "Die whale"],]
    show screen phonescr(messages, oldmessages)
    $ oldmessages = ["Die fatty", "Die whale"]
    $ renpy.pause(2)
    $ addmsg(["xxx","Ok?"]) 
    $ renpy.pause(2)
Thank you so much! Although this didn't exactly fix it on it's own I figured out the issue! I was referencing the updated version of oldmessages rather than the version the texts are supposed to use!

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot]