Having an issue with text message code

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
Gushi
Newbie
Posts: 24
Joined: Sun Apr 01, 2018 3:25 pm
Projects: Project 4th Wall
itch: https://umberbridge.
Contact:

Having an issue with text message code

#1 Post by Gushi »

I'm using Littanana's Text message code and I'm trying to make the color of the bubble change depending on who's talking by using a tag to replace the color string, this is my code up to where the error seems to be occurring.

Code: Select all

init:
    image phone = "images/Other_artwork/Phone_stuff/Phone.png"
    default bubble_color = "#ffffff"
    
##Picking up the phone
transform phone_pickup:
    yalign 0.0 xalign 0.5
    easein 0.3

transform phone_hide:
    yalign 1.0 xalign 0.5
    yoffset 100
    easein 0.3 yoffset 1300


transform phone_message_bubble_tip:
    xoffset 10
    yoffset 1

transform phone_message_bubble_tip2:
    xoffset 165
    yoffset 1

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

## Messages
init 5:
    style phone_message_vbox:
        xalign 0.52
        yalign 0
        ypos 180
        xsize 360
        xoffset -40

    style phone_message_frame:
        ypadding 10
        xpadding 10
        background Solid("[bubble_color]")
when I try to run the project I get this traceback error and I'm not sure what it's trying to tell me, I would assume that the tag would work just fine?

Code: Select all

I'm sorry, but an uncaught exception occurred.

After initialization, but before game start.
  File "renpy/common/00start.rpy", line 82, in _init_language
    renpy.change_language(language)
  File "game/phone.rpy", line 50, in <module>
    background Solid("[bubble_color]")
Exception: Color string u'[bubble_color]' must be 3, 4, 6, or 8 hex digits long.

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Having an issue with text message code

#2 Post by Alex »

The program complaines that it expected something like "#fff" as an argument for Solid statement, but got some text ("[bubble_color]").

If you want to use a variable for color, then it should look like

Code: Select all

Solid(bubble_color)
(without quotes, so the program could understand that this is a variable).

Variable in square brackets is used if you want tho show its value in text line - https://www.renpy.org/doc/html/text.htm ... ating-data

Gushi
Newbie
Posts: 24
Joined: Sun Apr 01, 2018 3:25 pm
Projects: Project 4th Wall
itch: https://umberbridge.
Contact:

Re: Having an issue with text message code

#3 Post by Gushi »

I have attempted that and it's giving me this traceback

Code: Select all

I'm sorry, but an uncaught exception occurred.

After initialization, but before game start.
  File "renpy/common/00start.rpy", line 82, in _init_language
    renpy.change_language(language)
  File "game/phone.rpy", line 50, in <module>
    background Solid(bubble_color)
NameError: name 'bubble_color' is not defined
How come it's saying it isn't defined when I defined it a couple lines before?

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Having an issue with text message code

#4 Post by Alex »

Hmm... as documentation says
"The init python statement runs Python at initialization time, before the game loads." (https://www.renpy.org/doc/html/python.h ... -statement)

"The default statement sets a single variable to a value if that variable is not defined when the game starts, or after a new game is loaded. When the variable points is not defined at game start, this statement is equivalent to:"

Code: Select all

label start:
    $ points = 0
(https://www.renpy.org/doc/html/python.h ... -statement).

That means, that 'bubble_color' will be set at the game start, but style expects its value at init time...

"As Ren'Py builds styles on startup, named styles should not be changed outside of a style statement or init block." (https://www.renpy.org/doc/html/style.ht ... nheritance - end of section).

"Warning
Named styles are not saved as part of the per-game data. This means that changes to them will not be persisted through a save and load cycle." (https://www.renpy.org/doc/html/style.ht ... -functions).


So, try to set this dynamic background not as a part of the style, but directly for the frame, like

Code: Select all

default bubble_color = "#c0c"

screen bttns():
    
    frame:
        style "phone_message_frame"
        background Solid(bubble_color)
        align(0.05, 0.1)
        vbox:
            textbutton "Scr 1" action NullAction()
            textbutton "Scr 2" action NullAction()

label start:
    show screen bttns
    "..."
    $ bubble_color = "#c00"
    "... ..."
    "?!"
Gushi wrote: Tue Feb 25, 2020 3:55 pm ...How come it's saying it isn't defined when I defined it a couple lines before?
Check this post viewtopic.php?f=51&t=39572 to confuse yourself a bit more...))

Post Reply

Who is online

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