I've been testing this for a while with different images and I've found that some images are properly added to the list but some are not. The problem seems to be that Ren'Py searches tags in the image file name as well as the variable name.
Unfortunately for this approach to work, the image file names must have underscores instead of spaces to separate words, or else Ren'Py will treat the spaces in their name as tags, adding them to the name generated by the function and thus making it different from the name you ask for with get_image(). I couldn't find a way to specify that I only want the variable names, as I can't access (and don't really want to mess with) built-in internal functions.
This is what I've got so far:
Code: Select all
image eileen pose1 smile = "eileen_pose_smile.png" #It works well with this image.
image mary pose1 smile = "mary pose smile.png" #With this one it doesn't because of different name
#For it to work, the filename must be the same as the image file, or alternatively, have no spaces
init python:
def get_showing_images(layer='master'):
img_list = []
tags = renpy.get_showing_tags(layer)
for i in list(tags):
if renpy.showing(i, layer):
tag_name = i
atrb = renpy.get_ordered_image_attributes(tag_name)
for a in atrb:
tag_name += ' ' + a
img_list.append(tag_name)
return img_list
def get_image(tag, layer='master'):
images = get_showing_images(layer)
if tag in images:
return tag
else:
return None
default test1 = None
default test2 = None
label start:
show eileen pose1 smile with dissolve
show mary pose1 smile at right with dissolve
$ test1 = get_showing_images('master')
"[test1]" #['eileen pose 1 smile', 'mary pose1 pose smile']
$ test2 = get_image('eileen pose1 smile', 'master')
"[test2]" # 'eileen pose1 smile'
$ test2 = get_image('mary pose1 smile', 'master')
"[test2]" # None, because error explained above. If names match, this works.
return
This is as far as I can go with this, if it still doens't help I hope that someone more experienced in Ren'Py's inner workings is able to offer a better solution.