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.
Hello! I am having issues with the drag & drop function. The way it works right now is that it makes a list of each item in a list and puts them on the screen to drag and drop. This works great! But only if the items are in a certain order in the list. The player will be able to add items to the list in any order they want/discover them in any order so they will show up differently. If the player discovers the one certain item first then the others, it works fine. But if they choose to start with any others, they don't drag anymore.
Screen code:
screen seeItems:
modal True
zorder 5
image "gui/popup.png"
image selectedItem.image zoom 0.5 align(0.5, 0.2)
draggroup:
drag:
drag_name selectedItem.n
xpos 0.45
ypos 0.25
drag_raise True
draggable False
droppable True
child "gui/dropArea.png"
for index, i in enumerate(itemList):
drag:
drag_name i.n
dragged ItemDrag
drag_raise True
draggable True
droppable False
if not i == selectedItem:
image i.image zoom 0.2
ypos 0.65
##This is here to attempt to center all of the draggable items but this doesn't exactly work too well either when it comes to the items being in a certain order
if itemList.index(i) > itemList.index(selectedItem):
xpos 0.5 - (len(itemList) + 1) * 0.1 / 2 + 0.1 * (index)
else:
xpos 0.5 - (len(itemList)) * 0.1 / 2 + 0.1 * (index)
textbutton "Exit" action Hide('seeItems') align(0.5, 0.9)
I've noticed that misclicking/clicking a lot tends to make the drag & drop stop working altogether as well. What I mean by 'not working' in both cases is that the draggable items 'freeze' and stop being draggable. Am I coding something wrong?
It's a bit unsettling and funny that you use the name "index" as the counting variable and "i" as the item, while everybody usually uses "i" as a counter for enumerate. This will confuse programmers that try to use your code, so good job.
Funny as well, I actually had to look up if "not" is evaluated after "==", which it is. Wouldn't have guessed it. Otherwise "not i" would result into "False" (since i is some object) which would probably never be equal to selectedItem. By the way, this is the standard:
m_from_space wrote: ↑Sat Dec 16, 2023 7:35 am
This will confuse programmers that try to use your code, so good job.
I'm sorry you were confused, it really wasn't my intention. I'm learning by myself, so if I see other guides in python or other people fix their problems like that, that's how my own code skills tend to develop :p If there are standards within programming groups then I figure it out as I go. It's just a learning process.
Not sure about your problem. What does the function "ItemDrag" do, that is called after you drag something?
As for the function, it's mostly just a lot of testing, but I find that if I comment it out of the screen, it still has the same issues. It's supposed to snap the moved item back to its original position for now.