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.
-
Reikun
- Miko-Class Veteran
- Posts: 565
- Joined: Tue Dec 20, 2011 9:57 pm
- Completed: Mnemonic Devices, Ciikos Bridge, Helena's Flowers, The Madness
- Projects: Fox in the Hollyhocks
- Organization: skyharborr
- itch: skyharborr
-
Contact:
#1
Post
by Reikun » Sun Jul 03, 2022 3:59 am
Sorry if this has an obvious solution. I'm a noob
I'm trying to have an image build-up/change over the course of the story depending on how the story progresses (there is some randomness involved). I want it to show up in the same state every time until it gets added to, and then to keep those additions. I put all the possible additions into groups like:
Code: Select all
layeredimage loc4d:
always:
"loc4_base"
always:
pos (410,420)
"loc4_piece_g"
group piece2:
pos (860,420)
attribute l_piece2:
"loc4_piece_l"
attribute b_piece2:
"loc4_piece_b"
attribute r_piece2:
"loc4_piece_r"
attribute m_piece2:
"loc4_piece_m"
attribute a_piece2:
"loc4_piece_a"
group piece3:
pos (1340,420)
attribute l_piece3:
"loc4_piece_l"
attribute b_piece3:
"loc4_piece_b"
attribute r_piece3:
"loc4_piece_r"
attribute m_piece3:
"loc4_piece_m"
attribute a_piece3:
"loc4_piece_a"
(It's has more groups but I cut it down because it's repetitive). I'm showing it in-game with this:
Code: Select all
scene loc4
show loc4d
with dissolve
And trying to make changes/add pieces like this:
Code: Select all
if part == 3:
if person == "Lucius":
scene loc4
show loc4d l_piece2
with dissolve
elif person == "Bugra":
scene loc4
show loc4d b_piece2
with dissolve
elif person == "Rian":
scene loc4
show loc4d r_piece2
with dissolve
elif person == "Mozelle":
scene loc4
show loc4d m_piece2
with dissolve
elif person == "Aiza":
scene loc4
show loc4d a_piece2
with dissolve
elif part == 2:
if person == "Lucius":
scene loc4
show loc4d l_piece3
with dissolve
elif person == "Bugra":
scene loc4
show loc4d b_piece3
with dissolve
elif person == "Rian":
scene loc4
show loc4d r_piece3
with dissolve
elif person == "Mozelle":
scene loc4
show loc4d m_piece3
with dissolve
elif person == "Aiza":
scene loc4
show loc4d a_piece3
with dissolve
I was thinking that since the different parts are in different groups they would all stay/carry over the next time the image loc4d is shown but this isn't the case. I'm not really sure how to make the specific pieces stay/"become default" so that they'll show up every single time the image is shown. Any insight would be super appreciated.

✧

✧
fastest way to contact me: DM @skyharborr on twitter
-
m_from_space
- Veteran
- Posts: 302
- Joined: Sun Feb 21, 2021 3:36 am
-
Contact:
#2
Post
by m_from_space » Sun Jul 03, 2022 6:28 am
I don't know what your image is about (is it a map?), but make sure to understand layeredimages: using the keyword "group" is for showing only 1 item per group (you know that). But it's not about showing only 1 group with your image. So if somehow exclusively want one of the groups to show, just make two images out of it. I also don't understand why the same images are shown inside group "piece2" and "piece3", so what's the point of those groups? If piece2 and piece3 should only show depending on variable "part" I would suggest the following. Also here is the manual for layeredimages:
https://www.renpy.org/doc/html/layeredimage.html
Code: Select all
layeredimage loc4d_2:
always:
"loc4_base"
always:
pos (410,420)
"loc4_piece_g"
group pieces:
pos (860,420)
attribute Lucius:
"loc4_piece_l"
attribute Bugra:
"loc4_piece_b"
layeredimage loc4d_3:
always:
"loc4_base"
always:
pos (410,420)
"loc4_piece_g"
group pieces:
pos (860,420)
attribute Lucius:
"loc4_piece_l"
attribute Bugra:
"loc4_piece_b"
and then just show the image like this:
Code: Select all
default part = 2
default person = "Lucius"
label start:
show expression "loc4d_[part] [person]"
"Now let's change the person very easily..."
$ person = "Bugra"
"Or let's change the part:"
$ part = 3
"Done."
-
zmook
- Veteran
- Posts: 421
- Joined: Wed Aug 26, 2020 6:44 pm
-
Contact:
#3
Post
by zmook » Sun Jul 03, 2022 9:26 am
I don't think I understand what the logic is behind your structure of 'if part/if person', but it sounds like maybe you want to use a conditional in your layeredimage rather than attributes:
Code: Select all
layeredimage loc4d lucius:
always:
"loc4_base"
if part >= 2
"loc4_piece_l2"
if part >= 3:
"loc4_piece_l3"
layeredimage loc4d bugra:
always:
"loc4_base"
if part >= 2
"loc4_piece_b2"
if part >= 3:
"loc4_piece_b3"
or something like that? You can test variables inside a layeredimage, you don't have to just specify everything as attributes when shown.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
-
Reikun
- Miko-Class Veteran
- Posts: 565
- Joined: Tue Dec 20, 2011 9:57 pm
- Completed: Mnemonic Devices, Ciikos Bridge, Helena's Flowers, The Madness
- Projects: Fox in the Hollyhocks
- Organization: skyharborr
- itch: skyharborr
-
Contact:
#4
Post
by Reikun » Sun Jul 03, 2022 4:56 pm
The reason I reuse the same images under different groups is that they appear in different positions so the final image will be made up of a set of possible pieces arranged in a different order.
I guess I could just make a bunch of different layeredimage blocks that will display one piece each...
I'm trying to figure out how to use this
https://www.renpy.org/doc/html/layeredi ... #Attribute. I see that there's a "default" there which could be set to True? I don't know how to write it though. Would it be like:
Code: Select all
$ Attribute("piece2","l_piece2",default=True)
?

✧

✧
fastest way to contact me: DM @skyharborr on twitter
-
zmook
- Veteran
- Posts: 421
- Joined: Wed Aug 26, 2020 6:44 pm
-
Contact:
#5
Post
by zmook » Sun Jul 03, 2022 6:12 pm
"groups" are like slots where several different mutually-exclusive options could show up.
"attributes" are flags you can choose each time you display the image. For each attribute provided, each group will be checked to see if there's something that should be shown for that attribute. (Including two attributes with layer-images in the same group, is an error.)
"default" for attributes means "use this option if nothing else from this group is specified."
It is totally possible to move all of your "if part"/"if person" logic inside the layered image declaration so that you just do
"show loc4d" and it "magically" produces the right version based on the current values of "part" and "person". See my previous example. If that's not what you're asking for, please clarify the question.
Last edited by
zmook on Wed Jul 13, 2022 10:20 pm, edited 1 time in total.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM
-
Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
-
Contact:
#6
Post
by Ocelot » Mon Jul 04, 2022 4:57 am
You can try to use
attribute_function layered image property to define function, which will adjust used attributes depending on external data. Something like:
Code: Select all
# A set to store all attributes which should be shown
default loc4d_attributes = set()
init python:
# this function adds all attributes stored in loc4d_attributes to the set
# displayed attributes and returns the result.
def adjust_loc4d(attrs):
return attrs.union(store.loc4d_attributes)
layeredimage loc4d:
# Function to call to adjust attributes before showing
attribute_function adjust_loc4d
# The rest is the same
label somewhere_in_the_game:
# we add b_piece2 to set of always showing attributes
$ loc4d_attributes.add('b_piece2')
show loc4d # should use provided function to auto-adjust and show correct images
< < insert Rick Cook quote here > >
-
Reikun
- Miko-Class Veteran
- Posts: 565
- Joined: Tue Dec 20, 2011 9:57 pm
- Completed: Mnemonic Devices, Ciikos Bridge, Helena's Flowers, The Madness
- Projects: Fox in the Hollyhocks
- Organization: skyharborr
- itch: skyharborr
-
Contact:
#7
Post
by Reikun » Wed Jul 13, 2022 5:09 pm
Thanks for the suggestions everyone. I ended up putting a conditional inside the layeredimage with different variables for each slot I wanted a piece to appear in (so these variables would be default an empty string and later change to the name of the piece chosen over the course of the game, which would make the appropriate piece appear and stay there). Never did figure out how to use the Attribute() built in function tho lol

✧

✧
fastest way to contact me: DM @skyharborr on twitter
Users browsing this forum: Bing [Bot]