sam1993 wrote: ↑Mon Dec 06, 2021 2:42 pm
Between 0 and 3 characters will be shown in a room. I would like these characters to stand neatly next to eachother in the bottomleft of the screen.
If I understand correctly, you want to keep track of a list of characters, and draw them on the BodyScreen in the right places. It sounds like you're overcomplicating things.
I'm guessing the logic is probably that you want everyone to stand next to each other, no empty slots, filling the ones furthest in the corner first. For that all you need is a list of characters:
Code: Select all
$ npcsPresent = [npc1, npc2, npc3]
screen BodyScreen(npcsPresent):
for (i,npc) in enumerate(npcsPresent):
imagebutton:
zoom 0.40
xpos i * 0.15
ypos 0.38
idle npc.GetUIName()
focus_mask True
action Call("interact", "npc", npc)
[`enumerate` is a standard Python function that basically creates a loop counter for you.]
If you need the `slot#` transforms for reasons you haven't included in this question, that's easy enough, too:
Code: Select all
$ npcsPresent = [npc1, npc2, npc3]
define slotTransforms = [slotTransform1, slotTransform2, slotTransform3, slotTransform4]
screen BodyScreen(npcsPresent):
for (i,npc) in enumerate(npcsPresent):
imagebutton:
idle npc.GetUIName()
focus_mask True
action Call("interact", "npc", npc)
at slotTransforms[i]
The above just tracks which npc appears in which slot by their order in the list. If you want more control than that, such as because you might leave empty slots, you could do this:
Code: Select all
$ npcsPresent = [(npc1,3), (npc2,1)), ]
screen BodyScreen(npcsPresent):
for (npc, slot) in npcsPresent:
imagebutton:
idle npc.GetUIName()
focus_mask True
action Call("interact", "npc", npc)
at getattr(store, "slotTransform%d" % slot)
# (I like old-style %f substitutions in renpy because they cause less trouble
# with Ren'Py {} formatting)
I wouldn't actually recommend that, though, because now it's become possible to screw up by putting two characters in the same slot. It's always better to make errors impossible than to have to debug them. A less error-prone way to do the same thing would be to allow Nones as members of the npcsPresent list, and check for them before displaying:
Code: Select all
$ npcsPresent = [npc1, npc2, None, npc3]
screen BodyScreen(npcsPresent):
for (i,npc) in enumerate(npcsPresent):
if npc is not None:
imagebutton:
zoom 0.40
xpos i * 0.15
ypos 0.38
idle npc.GetUIName()
focus_mask True
action Call("interact", "npc", npc)