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.
chaging/replacing filenames in the show image action
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.
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.
-
- 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
You can try using ConditionSwitch for this.
Or use text interpolation.
Also, the show expression statement can be utilized as well.
There are other ways, these are only some.
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
Code: Select all
default alternative = "x"
image character happy = "character_[alternative]_happy.png"
label start:
show character happy
pause
$ alternative = "y"
show character happy
Code: Select all
default alternativedesign = True
label start:
show expression "character {} happy".format("y" if alternativedesign else "x")
Re: chaging/replacing filenames in the show image action
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
-
- 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
I think this is what you're looking for then:
https://www.renpy.org/doc/html/statemen ... renpy.show
https://www.renpy.org/doc/html/statemen ... renpy.show
- 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
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:
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 > >
Who is online
Users browsing this forum: Ahrefs [Bot], mirceea