chaging/replacing filenames in the show image action

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
xenosss
Newbie
Posts: 3
Joined: Fri Jun 09, 2023 12:29 am
Contact:

chaging/replacing filenames in the show image action

#1 Post by xenosss »

What I'd like to know is, what function can I use to replace the letter x with y in the following statement. Let's say I have a bunch of images named ''character x happy/sad/shocked" and ''character y happy/sad/shocked"
x and y are completely different designs.

if alternativedesign == true
x = y

show character x happy
show character1 x happy
show character2 x shocked

What I'd like to happen is that instead of showing my ''character x happy'' image, it'll show my ''character y happy'' image instead and so on.

To clarify, I'm not looking for alternative solutions, what I'm looking for is a function to replace x with y when I make the ''show'' action, not typing it manually for every image, since I'll have many designs that need replacing.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: chaging/replacing filenames in the show image action

#2 Post by enaielei »

You can try using ConditionSwitch for this.

Code: Select all

default alternativedesign = True

image character happy = ConditionSwitch(
    "alternativedesign", "character x happy",
    "True", "character y happy"
)

label start:
   show character happy
   pause
   $ alternativedesign = False
   show character happy
Or use text interpolation.

Code: Select all

default alternative = "x"

image character happy = "character_[alternative]_happy.png"

label start:
   show character happy
   pause
   $ alternative = "y"
   show character happy
Also, the show expression statement can be utilized as well.

Code: Select all

default alternativedesign = True

label start:
    show expression "character {} happy".format("y" if alternativedesign else "x")
There are other ways, these are only some.

xenosss
Newbie
Posts: 3
Joined: Fri Jun 09, 2023 12:29 am
Contact:

Re: chaging/replacing filenames in the show image action

#3 Post by xenosss »

enaielei wrote: Fri Jun 09, 2023 1:16 am label start:
show expression "character {} happy".format("y" if alternativedesign else "x")
[/code]
There are other ways, these are only some.
Thank you a lot for your swift reply, the ''show expression'' statement is the closest to what I've been looking for/can understand. the ideal would be a function I could write that replaces all my x's with y's in my ''show'' actions. So I could just write ''character x mood'' and just turn off/on the function to replace the x whenever needed.

If you don't happen to know of any renpy/python functions that allow for that, I still thank you for your insight and time

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: chaging/replacing filenames in the show image action

#4 Post by enaielei »

I think this is what you're looking for then:
https://www.renpy.org/doc/html/statemen ... renpy.show

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

Re: chaging/replacing filenames in the show image action

#5 Post by Ocelot »

If you are interested in making things correctly, ConditionSwitch or dynamic images (text interpolation) is the way.

If you are in "I cannot afford to edit thousands lines of code right now and I am fine with raising technical debt" situation, then https://www.renpy.org/doc/html/config.h ... attributes allows you to dynamically replace attributes.

You can use it like:

Code: Select all

default alternativedesign == True

init python:
    def replace_design(name):
        if getattr(store, "alternativedesign", False):  # I am not sure if prediction can happen during init phase, but let's cover that
            adjusted_name = (y if entry == x else entry for entry in name)
        else:
            adjusted_name = name
        return adjusted_name

define config.adjust_attributes[None] = replace_design
< < insert Rick Cook quote here > >

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], mirceea