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.
-
Feleven
- Newbie
- Posts: 10
- Joined: Tue Jun 01, 2021 10:23 am
-
Contact:
#1
Post
by Feleven » Thu Sep 23, 2021 10:50 am
I'm making a glossary and want to make textbuttons that change the character's picture. Atm I have a different set of buttons for each character but I'd like to make only 1 set for all of them. Just to tidy up.
It looks like this atm:
Code: Select all
textbutton "1" action SetVariable("boy.imageName", "gui/custom/glossary/boy_glossary1.webp")
textbutton "2" action SetVariable("boy.imageName", "gui/custom/glossary/boy_glossary2.webp")
Boy is the character's name.
I made a class with the selectedCharacter variable and this is how I tried to 'automate' the whole thing. The first part works fine. What bricks it is finding the file.
Code: Select all
textbutton "1" action SetVariable("selectedCharacter.imageName", "gui/custom/glossary/" + "selectedCharacter" + "_glossary1.webp")
""gui/custom/glossary/" + "selectedCharacter" + "_glossary1.webp"" just doesn't work. I also tried:
Code: Select all
"gui/custom/glossary/" + "[selectedCharacter]" + "_glossary1.webp"
"gui/custom/glossary/" + selectedCharacter + "_glossary1.webp"
This is the error I get:
Code: Select all
File "renpy/display/image.py", line 577, in _scope
return self.find_target(scope, update)
File "renpy/display/image.py", line 652, in find_target
raise Exception(error)
Exception: DynamicImage u'[selectedCharacter.imageName]': could not find image. (u'gui/custom/glossary/selectedCharacter_glossary1.webp')
Would appreciate any clues or help.
-
jeffster
- Regular
- Posts: 123
- Joined: Wed Feb 03, 2021 9:55 pm
-
Contact:
#2
Post
by jeffster » Thu Sep 23, 2021 2:02 pm
I think that in the right part of the assignment you should not quote out the variables names. I.e. the right way should be:
Code: Select all
"gui/custom/glossary/" + selectedCharacter + "_glossary1.webp")
However selectedCharacter should be a string if you want to use it as a part of a string.
But look here:
Code: Select all
textbutton "1" action SetVariable("selectedCharacter.imageName",
You use
selectedCharacter.imageName which means it's a complex object, not a string.
That object probably has a field like "name" or something, which would be the string you need.
Then the solution is:
Code: Select all
textbutton "1" action SetVariable("selectedCharacter.imageName",
"gui/custom/glossary/" + selectedCharacter.name + "_glossary1.webp")
-
Feleven
- Newbie
- Posts: 10
- Joined: Tue Jun 01, 2021 10:23 am
-
Contact:
#3
Post
by Feleven » Fri Sep 24, 2021 11:54 am
jeffster wrote: ↑Thu Sep 23, 2021 2:02 pm
You use
selectedCharacter.imageName which means it's a complex object, not a string.
That object probably has a field like "name" or something, which would be the string you need.
Then the solution is:
Code: Select all
textbutton "1" action SetVariable("selectedCharacter.imageName",
"gui/custom/glossary/" + selectedCharacter.name + "_glossary1.webp")
You're spot on right. Thank you.
I went from having repetitive screens and entries for each character to having the whole thing in 60 lines of code.