Ren'Py How to make characters that can call specific images based on folder and name like in Brothel King?

elhlyn

Member
Jul 5, 2017
210
969
As the title states, I'm curious to know if there is a specific way to generate characters that will utilize a specific image folder so if we have a character using the "Nami" Folder it will show only images of Nami whenever I have that character do something. I'm not asking how he does it specifically in that way, just wanted to know how it could be done and right syntax for it.


(I'd like to make something like Brothel king where it's very user friendly to add in your own characters, though in this case a heavy influnce of Fire Emblem 3 houses. just a pet project to get some practice with Python)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,969
16,222
As the title states, I'm curious to know if there is a specific way to generate characters that will utilize a specific image folder so if we have a character using the "Nami" Folder it will show only images of Nami whenever I have that character do something. I'm not asking how he does it specifically in that way, just wanted to know how it could be done and right syntax for it.
Hmm. Don't know how they did for this game, but one way to do it probably rely on the possibility to have text substitution for image path.

Therefore, the simplest way to do is to have a variable where the name of the character will be stored, and to have all the images stored in a directory at this name. Something that would looks like :
Code:
image charIdle = "images/characters/[charName]/idle.jpg"
image charSmile = "images/characters/[charName]/smile.jpg"
[...]
label whatever:
   $ charName = "Nami"
But this is really the simplest approach. To do it in a robust way, you should permit to have a different image format, and to handle missing images.
 
  • Like
Reactions: elhlyn

lordparcival

Member
Nov 29, 2020
138
214
You can put the Images in Subfolders and just call them normally with the name. The name has to be different if you have it in more then one folder though. At least thats what i found out.
My images are in different folders

Images\Charname\Image1.png
Images\Charname\Image2.png
Images\Charname2\c2image1.png

In my code i only call the image with scene c2image1 and it works just fine. So if you have different names for the Images you can just call them normally. RenPy will search all the Subfolders and choose the one which fits the name.
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,608
2,256
As a general rule of thumb, you are strongly advised to use lowercase folder and filenames. It's not mandatory, but it makes certain other tasks easier.

When RenPy starts up, it scans for any images in the /images/ folder and sub-folders and creates a displayable with a matching name. Except that displayable name will always be lowercase, regardless of the case of the original files.

For example...
Images\Background\mybg01.jpg -> image mybg01 = "/images/Background/mybg01.jpg".
Images\Charname\Image1.png -> image image1 = "/images/Charname/Image1.png".

There have a been a couple of people confused recently why scene mybg01 works while scene Image1 doesn't - thinking that the case of the filename is kept by RenPy. (btw, scene image1 would have worked, if people hadn't made assumptions).

It's a hard habit to pick up, if you are already used to Capitalizing things like that for readability. The python recommendation is to use underscores for readability instead. Something like "my_bg01" instead.

If you're doing it differently... No harm done. As long as you understand WHY you might need to end up coding image statements manually sometimes to keep the case of the filename/foldername.
 
  • Like
Reactions: lordparcival

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
10,969
16,222
You can put the Images in Subfolders and just call them normally with the name. The name has to be different if you have it in more then one folder though.
What is the opposite of the searched effect.

OP (indirectly) said that it's to offer the possibility to add your own characters in the game. What mean the images need to have the same name, but be located in different places. What also imply that you can't hard code it, because you don't know what will be the name of the character, nor how many characters will be added.
 

lordparcival

Member
Nov 29, 2020
138
214
What is the opposite of the searched effect.

OP (indirectly) said that it's to offer the possibility to add your own characters in the game. What mean the images need to have the same name, but be located in different places. What also imply that you can't hard code it, because you don't know what will be the name of the character, nor how many characters will be added.

Yeah you are correct. I read the question of OP wrong.

BUT you would be able to use that system anyway by using variables for the name.
I am not quite sure if that is possible when calling the Scene BG Images or Images in General.
But it would make it way easier then having to assign the whole path over and over.

So in order to do this you would create Folders for each Character and put the Images of that Character in there with the name of the char in front.

So lets say we have two characters named Jimmy and Bob

So you would create two Folders one called jimmy one called bob
Then put the images of each char in there separate folder.

bob\bob wallking.png
bob\bob standing.png
bob\bob leaning.png
jimmy\jimmy walking.png
jimmy\jimmy standing.png
jimmy\jimmy leaning.png

if we use those as Scene images you would call them like this

scene %(player_name)s walking
scene %(player_name)s standing
scene %(player_name)s leaning

I am not quite sure if this could work but from my coding experience it might work just fine. I would advise you to leave a space between the char name and the imagename itself so the Variable for the Playername would work.



EDIT:

Alright its not working exactly like this but there might be a way to use it like that with a different call though.


Parc
 
Last edited:

Jman9

Engaged Member
Jul 17, 2019
2,295
961
Kinda necro, but... What Brothel King does is rather complicated. In broad strokes:
  • Preload all images into a custom data structure, with some tools attached via a Picture class.
  • Use a very complex substitution scheme for image replacement for situations where there's no exact match. In fact, there's some muddling of waters even if an exact match exists.
  • Use a special screen for displaying most images.
The screen thing does have its drawbacks. Mostly a lack of full ATL support.

We also recently discovered that you can reference a script file's location from within, so you could use that, even to 'define' images.