[SOLVED]is it possible to use a full path instead of only an imagename when showing image in layer?

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
sam1993
Newbie
Posts: 7
Joined: Tue May 19, 2020 2:23 pm
Contact:

[SOLVED]is it possible to use a full path instead of only an imagename when showing image in layer?

#1 Post by sam1993 »

Hello,

I'm trying to find a simular functionality to the renpy.show() method for displaying (multiple) images on a layer.
From what I understand renpy will scan my images folder and with the filenames it finds I can display my images.
For reasons I won't get into I need the same functionality with a path instead of solely a filename.

for example.
if my images folder contains the following file: images/npcs/sam/body.png
I would currently do renpy.show(body).
But what I need is for the same functionality with class.method('images/npcs/sam/body.png')

Below is an example how the code would operate.

Code: Select all

label test:
    "an empty room"
    $ NPC.Show("sam")
    "sam entered the room"
    return

Code: Select all

class NPC(object):
        @staticmethod
        def Show(name):
            npc = world.GetNpc(name)
            renpy.show(npc.path) # npc.path contains the string 'images/npcs/sam/body.png'
            return
Does something like this exist in renpy? Does anyone know a way to create this functionality? Or is there anyone that can guide me in the right direction?
Anything would be appreciated.

thanks in advance!


EDIT:
A current route I am exploring is creating images in code and excluding the 'images/npcs' directory from being scanned for images.
This seems to work until I try to create the images inside my buildWorld() function where the following error is thrown
Exception: Images may only be declared inside init blocks

Code: Select all

init python:
    renpy.image("images/npcs/sam/body.png", Image("images/npcs/sam/body.png"))  <- Works


    class World(object):
            def __init__(self):
                self.npcsPath = "images/npcs"
                self.npcs = []

            def BuildWorld(self):              
                renpy.image("images/npcs/sam/body.png", Image("images/npcs/sam/body.png"))  <- Exception thrown
                
the search continues since in my BuildWorld() method I have code that fetches all files from my images folder and maps them into objects. it will be here that these images should be created.

EDIT EDIT:
I was being a little dumb dumb. I may have had my World class inside a init python block, but the code instantiating my world and calling the BuildWorld class were in a regular python block

So I changed

Code: Select all

label preloopinit:
    python:
        world = World()
        world.BuildWorld()
    return
    
to

Code: Select all

label preloopinit:
    init python:
        world = World()
        world.BuildWorld()
    return
Now by just naming the images after my full path I can use the renpy.show() as I want. Not the cleanest of solutions, but for my personal needs I will always be working with paths and custom methods to display my images so it's not that bad.

Now I only need to exclude the images/npcs folder from being automatically converted to Images to get rid of the duplicates.
Last edited by sam1993 on Sun Dec 05, 2021 6:06 am, edited 1 time in total.

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

Re: is it possible to use a full path instead of only an imagename when showing image in layer?

#2 Post by Ocelot »

Did you try to check documentation for renpy.show?

Code: Select all

renpy.show(name='npc', what=npc.path)
# name is a tag used to hide/modify displayable later
EDIT: that... quite a few edits. Anyway, if you want to disable automatic image definition and swith to complete control over what and how is defined, set config.automatic_images to None, alternatively, you can exclide specific prefixes with config.automatic_images_strip
< < insert Rick Cook quote here > >

sam1993
Newbie
Posts: 7
Joined: Tue May 19, 2020 2:23 pm
Contact:

Re: is it possible to use a full path instead of only an imagename when showing image in layer?

#3 Post by sam1993 »

Ocelot wrote: Sat Dec 04, 2021 4:50 pm Did you try to check documentation for renpy.show?

Code: Select all

renpy.show(name='npc', what=npc.path)
# name is a tag used to hide/modify displayable later
Thank you for your response.
Yes, I did check the documentation before creating this post.
Sadly I run into the same problem when using the 'what' parameter as well. Where giving it the value of the filename works, but giving it the full path will not.
Ocelot wrote: Sat Dec 04, 2021 4:50 pm EDIT: that... quite a few edits. Anyway, if you want to disable automatic image definition and swith to complete control over what and how is defined, set config.automatic_images to None, alternatively, you can exclide specific prefixes with config.automatic_images_strip
Yeah...I'm using the forum as my own personal rubber duck lmao.
I did come across these configuration options. I'm going to try and implement them tomorrow.

Thank again for your input.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: is it possible to use a full path instead of only an imagename when showing image in layer?

#4 Post by zmook »

You could maybe use Renpy with the flow instead of fighting it, if you rename your images like "images/npcs/sam body.png", and store "sam body" in npc.imagename instead of "images/npcs/sam/body.png" in npc.path. Though I understand the feeling if, like Harold and Kumar, you've already gone too far to turn back now.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

sam1993
Newbie
Posts: 7
Joined: Tue May 19, 2020 2:23 pm
Contact:

Re: is it possible to use a full path instead of only an imagename when showing image in layer?

#5 Post by sam1993 »

zmook wrote: Sat Dec 04, 2021 6:01 pm You could maybe use Renpy with the flow instead of fighting it, if you rename your images like "images/npcs/sam body.png", and store "sam body" in npc.imagename instead of "images/npcs/sam/body.png" in npc.path. Though I understand the feeling if, like Harold and Kumar, you've already gone too far to turn back now.
I understand where you are coming from. I am familiar with the intended way of working, but for this particular project I cannot guarantee that the filenames will be unique. And there are going to be a lot of them. To save me from the hassle in the future I wanted to tackle this from the start and ensure I always have a unique name.

Thank you for the input!

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: is it possible to use a full path instead of only an imagename when showing image in layer?

#6 Post by zmook »

Just a suggestion, but you could throw in some validation in an "if debug" block, to check that the filenames *are* unique? If you aren't the only one adding images, you could at least check that everyone follows the rules.

Code: Select all

if debug:
    seen = {}
    for f in renpy.list_files():
        if not f.startswith("/images"):
                continue
        basename = f.split("/")[-1]
        if basename in seen:
                raise Exception("duplicate  image name: " + f)
        else:
                seen[basename] = True
    seen = None
Eh, if you know your circumstances and this won't work, you'll have to just get really intimate with Ren'py automatic image creation.
Last edited by zmook on Sun Dec 05, 2021 11:51 am, edited 1 time in total.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

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

Re: is it possible to use a full path instead of only an imagename when showing image in layer?

#7 Post by Ocelot »

sam1993 wrote: Sat Dec 04, 2021 5:32 pm
Ocelot wrote: Sat Dec 04, 2021 4:50 pm Did you try to check documentation for renpy.show?

Code: Select all

renpy.show(name='npc', what=npc.path)
# name is a tag used to hide/modify displayable later
Thank you for your response.
Yes, I did check the documentation before creating this post.
Sadly I run into the same problem when using the 'what' parameter as well. Where giving it the value of the filename works, but giving it the full path will not.
I might falsely expect that it will wrap string in varable into displayable automatically. But you can always do it manually:

Code: Select all

renpy.show(name='npc', what=Image(npc.path))
I just tested it, and it should work.
Image
(ignore size... incompatibilities, I just grabbed first image I found)
< < insert Rick Cook quote here > >

sam1993
Newbie
Posts: 7
Joined: Tue May 19, 2020 2:23 pm
Contact:

Re: is it possible to use a full path instead of only an imagename when showing image in layer?

#8 Post by sam1993 »

Ocelot wrote: Sun Dec 05, 2021 3:41 am
sam1993 wrote: Sat Dec 04, 2021 5:32 pm
Ocelot wrote: Sat Dec 04, 2021 4:50 pm Did you try to check documentation for renpy.show?

Code: Select all

renpy.show(name='npc', what=npc.path)
# name is a tag used to hide/modify displayable later
Thank you for your response.
Yes, I did check the documentation before creating this post.
Sadly I run into the same problem when using the 'what' parameter as well. Where giving it the value of the filename works, but giving it the full path will not.
I might falsely expect that it will wrap string in varable into displayable automatically. But you can always do it manually:

Code: Select all

renpy.show(name='npc', what=Image(npc.path))
I just tested it, and it should work.
Image
(ignore size... incompatibilities, I just grabbed first image I found)
This works like a charm!
I will be implementing this way of working. Thank you for your help!

sam1993
Newbie
Posts: 7
Joined: Tue May 19, 2020 2:23 pm
Contact:

Re: is it possible to use a full path instead of only an imagename when showing image in layer?

#9 Post by sam1993 »

zmook wrote: Sat Dec 04, 2021 7:35 pm Just a suggestion, but you could throw in some validation in an "if debug" block, to check that the filenames *are* unique? If you aren't the only one adding images, you could at least check that everyone follows the rules.

Code: Select all

if debug:
    seen = {}
    for f in renpy.list_files():
        if not f.startswith("/images"):
                continue
        basename = f.split("/")[-1]
        if basename in seen:
                raise Exception("duplicate  image name: " + f)
        else:
                seen[basename] = True
    seen = {}
Eh, if you know your circumstances and this won't work, you'll have to just get really intimate with Ren'py automatic image creation.
With the combined effort of the people helping me in this thread, I've come to a solution I am happy with!
I appreciate your help! Thank you.

Post Reply

Who is online

Users browsing this forum: No registered users