how to parse a variable in image text [solved]

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
william_dickson
Newbie
Posts: 3
Joined: Tue Apr 23, 2019 1:18 am
Completed: >10 html5/canvas javascript browser games
Organization: eroticinteractivegames.com
Location: Glasgow, Scotland
Contact:

how to parse a variable in image text [solved]

#1 Post by william_dickson » Tue Apr 23, 2019 1:47 am

Hi
First question after registration since I can usually find the answer using google (and ending up on a post on here) but not this time. I hope I'm in the right sub-forum, please forgive me if I'm not and please point me to the right one :)

Code: Select all

python:
        name = renpy.input(_("What's her name?"))
        name = name.strip() or __("So Lazy")
This will work:

Code: Select all

narrator "Her name is [name]"
This won't work:

Code: Select all

image hername = Text("Her name \nis [name]", style="sayText_b26_trf")
show hername
The style takes care of the positioning and all that and works with all image-text without variables (I'm placing text as image in speech bubbles)
I've tried declaring the variable default name="noname", I've tried combining text strings, you name it.

KeyError u'name'

I must be missing something incredibly basic and am, admittedly, very n00b. Any help appreciated.

Edit (solved). Use

Code: Select all

show expression Text("Hey! [name] \nListen up!", style="sayText_b26_trf")
Fially found it in viewtopic.php?t=28500. Kudos go there!
Last edited by william_dickson on Tue Apr 30, 2019 11:58 am, edited 1 time in total.

User avatar
isobellesophia
Miko-Class Veteran
Posts: 787
Joined: Mon Jan 07, 2019 2:55 am
Projects: Maddox and Friends 2020 aka (AI Teacher), Friendly Universities 2020-2021 (Soon)
Organization: Friendly Teachers series
Deviantart: SophBelle
itch: .......
Location: Philippines, Mindanao
Contact:

Re: how to parse a variable in image text

#2 Post by isobellesophia » Tue Apr 23, 2019 2:12 am

Code: Select all

image name = Text("Her name is [name]", style="sayText_b26_trf")
show name
perhaps?
I am a friendly user, please respect and have a good day..

Be safe for the pandemic everyone, god bless.


Working on a talking simulation game for everyone, except children.

Maddox Everyday Talk!
Is my very very main project, not contain 13 below.

Main project here viewtopic.php?f=43&t=56564
Image

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

Re: how to parse a variable in image text

#3 Post by philat » Tue Apr 23, 2019 2:21 am

The problem is the image is defined once taking the value of name at the time of definition and isn't updated. (Also possibly the order the variable being defined -- have you added a default name = None or something at the beginning?) I'd try ParameterizedText (https://www.renpy.org/doc/html/text.htm ... erizedText ).

Code: Select all

default name = "None"
image hername = ParameterizedText(style="sayText_b26_trf")

label start:
    show hername "Her name\nis [name]" #ETA because I realized it was longer than just the name. Works either way though.
Last edited by philat on Tue Apr 23, 2019 2:25 am, edited 2 times in total.

william_dickson
Newbie
Posts: 3
Joined: Tue Apr 23, 2019 1:18 am
Completed: >10 html5/canvas javascript browser games
Organization: eroticinteractivegames.com
Location: Glasgow, Scotland
Contact:

Re: how to parse a variable in image text

#4 Post by william_dickson » Tue Apr 23, 2019 2:22 am

Nope, \n is a new line, works like a charm, no difference without it though
isobellesophia wrote:
Tue Apr 23, 2019 2:12 am

Code: Select all

image name = Text("Her name is [name]", style="sayText_b26_trf")
show name
perhaps?

william_dickson
Newbie
Posts: 3
Joined: Tue Apr 23, 2019 1:18 am
Completed: >10 html5/canvas javascript browser games
Organization: eroticinteractivegames.com
Location: Glasgow, Scotland
Contact:

Re: how to parse a variable in image text

#5 Post by william_dickson » Tue Apr 30, 2019 11:48 am

philat wrote:
Tue Apr 23, 2019 2:21 am
The problem is the image is defined once taking the value of name at the time of definition and isn't updated. (Also possibly the order the variable being defined -- have you added a default name = None or something at the beginning?) I'd try ParameterizedText (https://www.renpy.org/doc/html/text.htm ... erizedText ).

Code: Select all

default name = "None"
image hername = ParameterizedText(style="sayText_b26_trf")

label start:
    show hername "Her name\nis [name]" #ETA because I realized it was longer than just the name. Works either way though.
Thanks, couldn't get this to work but this did:

Code: Select all

show expression Text("Hey! [name] \nListen up!", style="sayText_b26_trf")

Post Reply

Who is online

Users browsing this forum: Nikel