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.
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:
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
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
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."
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:
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
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:
"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
You can try to use attribute_function layered image property to define function, which will adjust used attributes depending on external data. Something like:
# 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
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