How to define image to a Variable? 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
NickelBuckle9
Regular
Posts: 36
Joined: Wed Sep 14, 2011 3:47 pm
Completed: MiniBot
Projects: Ah! Peku, Pokemon Trainer Game (untitled)
Location: United States - East Coast
Contact:

How to define image to a Variable? SOLVED

#1 Post by NickelBuckle9 »

So, I figured out how to get the variables working. I now have a variable "HAIR" which specifies the correct image file in the correct format:
Pictures/H1A.png

by using something like this:

Code: Select all

$ HAIR = "Pictures/H" + HAIRSTYLE + HAIRCOLOR + ".png"
Is there any way to define the image "hair" by using this variable?

Code: Select all

image hair = HAIR

image hair = str(HAIR)

#and...

image hair = "[HAIR]"

# don't work  D:  What do I do???
image hair = "[HAIR]" comes the closet to working, as it runs smoothly until it must display the image. However, red text appears that says:
"Image 'Pictures/H25B.png' not found"

Any ideas? Thank you so much!
Last edited by NickelBuckle9 on Fri Dec 23, 2011 12:16 pm, edited 4 times in total.
Image
Completed Projects:
* MiniBot *
http://www.youtube.com/watch?v=xR6Ru9-vlic
(Check video details for download links)
http://nickel-buckle-9.deviantart.com/

Mild Curry
Regular
Posts: 107
Joined: Fri Jul 02, 2010 3:03 pm
Projects: That's The Way The Cookie Crumbles
Organization: TwinTurtle Games
Contact:

Re: Simple Variables not working...?

#2 Post by Mild Curry »

Hmm...try it this way:

Code: Select all

$ HAIR = "Pictures/H" + str(HAIRSTYLE) + str(HAIRCOLOR) + ".png"
It's basically assuring the game that those variables are strings too, and therefore part of the larger string.

NickelBuckle9
Regular
Posts: 36
Joined: Wed Sep 14, 2011 3:47 pm
Completed: MiniBot
Projects: Ah! Peku, Pokemon Trainer Game (untitled)
Location: United States - East Coast
Contact:

Re: Simple Variables not working...?

#3 Post by NickelBuckle9 »

Mild Curry wrote:Hmm...try it this way:

Code: Select all

$ HAIR = "Pictures/H" + str(HAIRSTYLE) + str(HAIRCOLOR) + ".png"
It's basically assuring the game that those variables are strings too, and therefore part of the larger string.

Thanks! ...but I managed to figure out why it wasn't working. Apparently it needs to be in the actual game script after the start label, not at the beginning.

Would you have any idea how to use this variable to define an image? I edited the topic as you replied it seems. >_>
Image
Completed Projects:
* MiniBot *
http://www.youtube.com/watch?v=xR6Ru9-vlic
(Check video details for download links)
http://nickel-buckle-9.deviantart.com/

Mild Curry
Regular
Posts: 107
Joined: Fri Jul 02, 2010 3:03 pm
Projects: That's The Way The Cookie Crumbles
Organization: TwinTurtle Games
Contact:

Re: How to define image to a Variable?

#4 Post by Mild Curry »

Hmm...that's odd. "image hair = HAIR" works fine for me.

Well, anyway, you don't want to define 'hair' as an image. I don't think images defined in init blocks can be changed.

Try this:

Code: Select all

  $ HAIR = "Pictures/H" + HAIRSTYLE + HAIRCOLOR + ".png"
  show expression HAIR
*sorry if this is irrelevant again*

NickelBuckle9
Regular
Posts: 36
Joined: Wed Sep 14, 2011 3:47 pm
Completed: MiniBot
Projects: Ah! Peku, Pokemon Trainer Game (untitled)
Location: United States - East Coast
Contact:

Re: How to define image to a Variable?

#5 Post by NickelBuckle9 »

Mild Curry wrote:Hmm...that's odd. "image hair = HAIR" works fine for me.

Well, anyway, you don't want to define 'hair' as an image. I don't think images defined in init blocks can be changed.

Try this:

Code: Select all

  $ HAIR = "Pictures/H" + HAIRSTYLE + HAIRCOLOR + ".png"
  show expression HAIR
*sorry if this is irrelevant again*

AHHHH! It worked! Thank you so much! You just saved my over 150 lines of repetitive code, haha. <3
Image
Completed Projects:
* MiniBot *
http://www.youtube.com/watch?v=xR6Ru9-vlic
(Check video details for download links)
http://nickel-buckle-9.deviantart.com/

Post Reply

Who is online

Users browsing this forum: No registered users