is there a way to group images?

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
hiera
Newbie
Posts: 13
Joined: Sun Aug 07, 2022 3:15 pm
Projects: Kill The Night
itch: hiera
Discord: hier.a
Contact:

is there a way to group images?

#1 Post by hiera »

Code: Select all

############ characters #####################################

define sh = Character('Shiori', callback=name_callback, cb_name='sh', kind=nvl, image='sh' )

################ IMAGES #######################

image shiori1 = At('shiori1', sprite_highlight('shiori1'))
image shiori1c = At('shiori1c', sprite_highlight('shiori1c'))
image shiori2 = At('shiori2', sprite_highlight('shiori2'))
image shiori2c = At('shiori2c', sprite_highlight('shiori2c'))
in order to use this auto highlight plugin: https://wattson.itch.io/renpy-auto-highlight

you'd need to apply callback to every image (if ur using individual sprites like i am) so, is it possible group all of these images into a group or image called 'sh' instead of mentioning them each time in the define section? (there's a lot more images apart from the 4)

thank you in advance

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: is there a way to group images?

#2 Post by jeffster »

The plugin description says: "if you're using individual sprites, you'll have to be sure this is applied to every one".

To write it in shorter way, it's possible to put the image names into a list and apply the plugin to every list member in a cycle. Example:

Code: Select all

init python:
    sh_list = ["shiori1", "shiori1c", "shiori2", "shiori2c"]     # and so on
    for s in sh_list:
        renpy.image(s, At("images/{}.webp".format(s), sprite_highlight(s)))
assuming that all picture files are named "images/{}.webp".

Maybe there is a more efficient way to do all that, but it might need to modify the plugin, so you might want to contact its author asking about the enhancement.

EDIT: I used setattr(store, s, ...) to assign images to variables, but that's not necessary. Just renpy.image(...) is sufficient.

hiera
Newbie
Posts: 13
Joined: Sun Aug 07, 2022 3:15 pm
Projects: Kill The Night
itch: hiera
Discord: hier.a
Contact:

Re: is there a way to group images?

#3 Post by hiera »

my bad, i didn't see this reply earlier

thank you, i'll test it out

hiera
Newbie
Posts: 13
Joined: Sun Aug 07, 2022 3:15 pm
Projects: Kill The Night
itch: hiera
Discord: hier.a
Contact:

Re: is there a way to group images?

#4 Post by hiera »

jeffster wrote: Fri Jun 02, 2023 3:13 pm

Code: Select all

    for s in sh_list:
        renpy.image(s, At("images/{}.webp".format(s), sprite_highlight(s)))
assuming that all picture files are named "images/{}.webp".
do you mind explaining what you did here? i use .png, so how would that work?

jeffster
Veteran
Posts: 409
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: is there a way to group images?

#5 Post by jeffster »

hiera wrote: Tue Jun 27, 2023 4:42 am
jeffster wrote: Fri Jun 02, 2023 3:13 pm

Code: Select all

    for s in sh_list:
        renpy.image(s, At("images/{}.webp".format(s), sprite_highlight(s)))
assuming that all picture files are named "images/{}.webp".
do you mind explaining what you did here? i use .png, so how would that work?
Some time has passed since we discussed this topic, but I will answer just in case.

Code: Select all

"images/{}.webp".format(s)
is a Python construction. It substitutes "{}" with the value in "format()". See
https://pyformat.info

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

Re: is there a way to group images?

#6 Post by m_from_space »

jeffster wrote: Mon Feb 19, 2024 11:10 am is a Python construction. It substitutes "{}" with the value in "format()". See
https://pyformat.info
I recommend using f-strings whenever possible, they are just easier to read.

Code: Select all

renpy.image(s, At(f"images/{s}.webp", sprite_highlight(s)))

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]