SOLVED: Using a variable for screen name in Character object

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
webryder
Regular
Posts: 40
Joined: Thu Feb 06, 2014 9:46 pm
Contact:

SOLVED: Using a variable for screen name in Character object

#1 Post by webryder »

Hi all,

I am trying to switch text boxes depending on certain in-game conditions. For example, a character's dialogue box changes depending on where he is on the screen.

I tried to do it this way, but it didn't work:

Code: Select all

define hiroshi = Character(None, screen=speech_"bubble")
where "bubble" is a string variable defined in the game. For example, "bubble = center".

Does anyone have any suggestions on what I'm doing wrong in the character statement?

Thanks!
Last edited by webryder on Thu Jan 29, 2015 1:02 am, edited 1 time in total.

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

Re: Using a variable for screen name in Character object

#2 Post by philat »

Well, I don't know exactly how you're trying to implement anything but your current code combines a name (speech_) with a string ("bubble") in a way that probably throws up an error.

If what you're trying to do is eventually have screen be "screen_center" or "screen_left", etc., then it should probably be

Code: Select all

screen="speech_"+bubble
Haven't tested it, but the concatenation should work in principle.

webryder
Regular
Posts: 40
Joined: Thu Feb 06, 2014 9:46 pm
Contact:

Re: Using a variable for screen name in Character object

#3 Post by webryder »

I revised the character line to the following to try something different:

Code: Select all

define hiroshi = Character(None, window.background = "art/gui/Dialogue_"+bubble+".png")
but now I'm getting an error saying "Keyword can't be an expression." or something like that. THe idea is that bubble is a variable which can have string values like "center", "right", etc.

Any suggestions on how I get that dynamic filename to work?

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Using a variable for screen name in Character object

#4 Post by trooper6 »

I don't know the answer to your question...but you could do this as a work around:

Code: Select all

define hLeft = Character(None, window.background = "art/gui/Dialogue_Left.png")
define hRight = Character(None, window.background = "art/gui/Dialogue_Right.png")
define hCenter = Character(None, window.background = "art/gui/Dialogue_Center.png")

init -1 python:
    def h(what, bubble="center", **kwargs):
        if bubble == "left":
            hLeft(what, **kwargs)
        elif bubble == "right":
            hRight(what, **kwargs)
        elif bubble == "center":
            hCenter(what, **kwargs)

label start:
    $h("This text will show up using the left bubble.", "left")
    $h("This text will show up using the right bubble.", "right")
    $h("This text will show up using the center bubble.", "center)
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

webryder
Regular
Posts: 40
Joined: Thu Feb 06, 2014 9:46 pm
Contact:

Re: Using a variable for screen name in Character object

#5 Post by webryder »

I feel like such a doofus - LOL.

The main problem is I used a dot instead of an underscore. It works when I do this:

Code: Select all

define hiroshi = Character(None, window_background = SpeechBubble)
And I define SpeechBubble initially in an init -1 python statement and it looks like I can change it as needed, changing the text box.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Ocelot