Composite image questions--% wildcard tag?

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
edgebug
Regular
Posts: 41
Joined: Thu Jun 30, 2016 11:44 pm
Contact:

Composite image questions--% wildcard tag?

#1 Post by edgebug »

So I'm making a composite image for a character creator.

(0, 0), "images/hairunder/hunder[hair_type]/hunder[hair_type]_[hair_color].png",

now, sometimes, that file name doesn't exist. i don't NEED a 'hunder' image for every composite! ("hunder" means "hair under." Not every hairstyle is going to NEED an 'under' part.)

However, the game throws an error when I don't have those images. So I've been making dozens and dozens of blank PNGs numbered appropriately in order to fix this. It seems like this is a bad and hacky way to deal with this, haha.

Is there a better way? I tried using ONE blank image and naming it "hunder%_%.png", my idea being that it would be displayed whenever renpy didn't have another option. but that didn't work either.

How do I make it so that either NOTHING is showed when an image that doesn't exist is called, or that my blank "hunder%_%.png" is called when those unneeded 'hunder' images are called?

Any ideas? Am I missing something basic?

Thank you in advance!

User avatar
m_from_space
Miko-Class Veteran
Posts: 957
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Composite image questions--% wildcard tag?

#2 Post by m_from_space »

Uhm, why don't you just check using programming logic? If the hairstyle doesn't need a specific image, then create the composite without that image? Of course the game throws an error if you want to load an image, that's not there. That's a good game logic. ;)

You should really share more code so people actually know what you are doing. So I'm probaly not really answering your question with the following, but maybe I will by chance:

If you don't need a specific part as part of a composite, just add Null() to it instead or create the composite without it.

Code: Select all

haircut = Image("images/whatever.jpg")
if hair_type is in list_of_hairtypes_that_has_hunder:
    hairunder = Image("images/hairunder/hunder[hair_type]/hunder[hair_type]_[hair_color].png")
else:
    hairunder = Null()
final_cut = Composite((100, 100), (0,0), hairunder, (0,0), haircut)

edgebug
Regular
Posts: 41
Joined: Thu Jun 30, 2016 11:44 pm
Contact:

Re: Composite image questions--% wildcard tag?

#3 Post by edgebug »

Thank you for answering!!!

Okay, first of all, there's some more of the code.

Code: Select all

init:
    default body_type = 1
    default body_type_max = 4
    default hair_type = 1
    default hair_type_max = 6
    default hair_color = 1
    default hair_color_max = 13
    default face = 1
    default face_max = 5
    default skin_color = 1
    default skin_color_max = 9
    default eyes = 1
    default eyes_max = 3
    default eye_color = 1
    default eye_color_max = 13
    default mouth = 1
    default brows = 1
    default nose = 1
    default nose_max = 3

image mc = Composite(
    (467, 946),

    (0, 0), "images/bodies/body[body_type]/body[body_type]_[skin_color].png",
    (0, 0), "images/hairunder/hunder[hair_type]/hunder[hair_type]_[hair_color].png",
    (0, 0), "images/faces/face[face]/face[face]_[skin_color].png",
    (0, 0), "images/eyes/eyes[eyes]/eyes[eyes]_[eye_color].png",
    (0, 0), "images/eyebrows/brows[brows].png",
    (0, 0), "images/mouths/mouth[mouth].png",
    (0, 0), "images/noses/nose[nose].png",
    (0, 0), "images/hair/hair[hair_type]/hair[hair_type]_[hair_color].png",
)
There it is-- the entire composite image :)

Then we have a screen where you can change the values of everything when you click arrows. If you need the code for that, I can grab it too.

I'm not sure how exactly to apply your advice. I'm not a programmer, I'm an artist, yknow? A little dumb when it comes to this kind of thing. Where would I make that "list of hairtypes that has hunder"? Can I really put if/else statements into the middle of all that code up there?

Thank you so much for your help. Is there anything I can do for you in return? (I'm an artist, I could draw you a portrait or something!)

edgebug
Regular
Posts: 41
Joined: Thu Jun 30, 2016 11:44 pm
Contact:

Re: Composite image questions--% wildcard tag?

#4 Post by edgebug »

This doesn't work... Invalid syntax, it says. :(

Code: Select all

init python:
    list_of_hairstyles_hunder = ["hair5", "hair6"]


image mc = Composite(
    (467, 946),

    (0, 0), "images/bodies/body[body_type]/body[body_type]_[skin_color].png",
    if "[hair_type]" is in list_of_hairstyles_hunder:
        (0, 0), "images/hairunder/hunder[hair_type]/hunder[hair_type]_[hair_color].png"

    (0, 0), "images/faces/face[face]/face[face]_[skin_color].png",
    (0, 0), "images/eyes/eyes[eyes]/eyes[eyes]_[eye_color].png",
    (0, 0), "images/eyebrows/brows[brows].png",
    (0, 0), "images/mouths/mouth[mouth].png",
    (0, 0), "images/noses/nose[nose].png",
    (0, 0), "images/hair/hair[hair_type]/hair[hair_type]_[hair_color].png",
)

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

Re: Composite image questions--% wildcard tag?

#5 Post by philat »

Try an inline conditional (caveat, haven't tried doing this, so perhaps it won't work.)

Code: Select all

image mc = Composite(
    (467, 946),

    (0, 0), "images/bodies/body[body_type]/body[body_type]_[skin_color].png",
    (0, 0), "images/hairunder/hunder[hair_type]/hunder[hair_type]_[hair_color].png" if (hair_type==5 or hair_type==6) else Null(width=1),
    (0, 0), "images/faces/face[face]/face[face]_[skin_color].png",
    (0, 0), "images/eyes/eyes[eyes]/eyes[eyes]_[eye_color].png",
    (0, 0), "images/eyebrows/brows[brows].png",
    (0, 0), "images/mouths/mouth[mouth].png",
    (0, 0), "images/noses/nose[nose].png",
    (0, 0), "images/hair/hair[hair_type]/hair[hair_type]_[hair_color].png",
)

edgebug
Regular
Posts: 41
Joined: Thu Jun 30, 2016 11:44 pm
Contact:

Re: Composite image questions--% wildcard tag?

#6 Post by edgebug »

Thank you for the help, but unfortunately it doesn't work :(

User avatar
m_from_space
Miko-Class Veteran
Posts: 957
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Composite image questions--% wildcard tag?

#7 Post by m_from_space »

Please provide error messages or descriptions to explain what exactly does not work. ;)

Try this instead:

Code: Select all

image mc = Composite(
        (467, 946),
        (0, 0), "images/bodies/body[body_type]/body[body_type]_[skin_color].png",
        (0, 0), "images/hairunder/hunder[hair_type]/hunder[hair_type]_[hair_color].png" if "[hair_type]" in ["5", "6"] else Null(),
        (0, 0), "images/faces/face[face]/face[face]_[skin_color].png",
        (0, 0), "images/eyes/eyes[eyes]/eyes[eyes]_[eye_color].png",
        (0, 0), "images/eyebrows/brows[brows].png",
        (0, 0), "images/mouths/mouth[mouth].png",
        (0, 0), "images/noses/nose[nose].png",
        (0, 0), "images/hair/hair[hair_type]/hair[hair_type]_[hair_color].png",
    )
edit:
The expression if "[hair_type]" doesn't really check the variable, so this isn't working. Using if hair_type will result in an error claiming the variable is not known. Sorry for that!
Last edited by m_from_space on Sat May 21, 2022 1:54 pm, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Composite image questions--% wildcard tag?

#8 Post by Ocelot »

Second argument expects Displayable, not python expression, this is not going to work. You can use Conditional for that instead.
< < insert Rick Cook quote here > >

User avatar
m_from_space
Miko-Class Veteran
Posts: 957
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Composite image questions--% wildcard tag?

#9 Post by m_from_space »

Ocelot wrote: Sat May 21, 2022 10:39 am Second argument expects Displayable, not python expression, this is not going to work. You can use Conditional for that instead.
Actually, the python expression isn't the problem, it works. But what's not working is checking the variable, since "hair_type" isn't available at the moment renpy is creating the image (it is for he image path though, don't understand it). It works if you define the variable not as "default", but inside a python init block. But then the variable wouldn't be available as part of the game. This is actually confusing me, since I never worked with dynamic images (the ones that have their paths dynamic through strings) using the image keyword.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Composite image questions--% wildcard tag?

#10 Post by Ocelot »

m_from_space wrote: Sat May 21, 2022 1:50 pm Actually, the python expression isn't the problem, it works. But what's not working is checking the variable, since "hair_type" isn't available at the moment renpy is creating the image (it is for he image path though, don't understand it). It works if you define the variable not as "default", but inside a python init block. But then the variable wouldn't be available as part of the game. This is actually confusing me, since I never worked with dynamic images (the ones that have their paths dynamic through strings) using the image keyword.
This is what what "not working" is. Statements taking "simple expression" can correctly interpret and execute python code at the moment you expect. In all other cases it is executed once during initialization and then no Python trace remains and no changes made during the game are picked.
< < insert Rick Cook quote here > >

edgebug
Regular
Posts: 41
Joined: Thu Jun 30, 2016 11:44 pm
Contact:

Re: Composite image questions--% wildcard tag?

#11 Post by edgebug »

Is this just not solvable, then? 😬

User avatar
m_from_space
Miko-Class Veteran
Posts: 957
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Composite image questions--% wildcard tag?

#12 Post by m_from_space »

I think I found what's going to work, seems like renpy got this all figured out again.

Code: Select all

default list_of_hunder = [5, 6]

image mc = Composite(
        (467, 946),
        (0, 0), "images/bodies/body[body_type]/body[body_type]_[skin_color].png",
        (0, 0), ConditionSwitch("hair_type in list_of_hunder", "images/hairunder/hunder[hair_type]/hunder[hair_type]_[hair_color].png", "True", Null()),
        (0, 0), "images/faces/face[face]/face[face]_[skin_color].png",
        (0, 0), "images/eyes/eyes[eyes]/eyes[eyes]_[eye_color].png",
        (0, 0), "images/eyebrows/brows[brows].png",
        (0, 0), "images/mouths/mouth[mouth].png",
        (0, 0), "images/noses/nose[nose].png",
        (0, 0), "images/hair/hair[hair_type]/hair[hair_type]_[hair_color].png"
    )

edgebug
Regular
Posts: 41
Joined: Thu Jun 30, 2016 11:44 pm
Contact:

Re: Composite image questions--% wildcard tag?

#13 Post by edgebug »

MY GOD, IT FREAKING WORKS.

You're a literal life saver. Thank you SO MUCH.

Post Reply

Who is online

Users browsing this forum: AWizardWithWords, Google [Bot]