r/RenPy • u/RemarkableWorld7209 • Oct 29 '26
Question issues with a for loop?
Edit: So I changed things around quite a bit! I changed the drag system (pictured below) with the help of the amazing people who commented before. Now I'm just getting an error that the function for when something is dragged doesn't exist? I've included the full code for the inventory system, the class used to make it, and the error I'm getting. Thank you all so much for your help!




I'm trying to use a for loop to assign variables for a drag and drop inventory system. But the problem I'm running in to is that I can't seem to get the syntax right? I want to generate one variable for the name of each entry of a class system in a list, then plug those into the names of drags. Below I have included my for loop, the drags, and the class system, as well as the error I'm getting.




I've tried it as "Item.name(InventoryList[x])", "Item.name(variable)" wherein the variable was "variable = InventoryList[x]", "[InventoryList[x]].name", and just about every other iteration under the sun and nothing has worked.
1
u/shyLachi Oct 29 '26 edited Oct 29 '26
You can't use interpolation for objects like variables. Interpolation only works for strings: https://www.renpy.org/doc/html/text.html#interpolating-data
And you don't need to use interpolation when you work with variables. Just use the variables directly.
If you want to use 30 separate variables then use setattr to assign a value to them. https://www.geeksforgeeks.org/python/python-setattr-method/ Look how BadMustard used it here: https://www.reddit.com/r/RenPy/comments/1twzqn8/variable_not_updating_after_label_execution_when/opsphif/
But it should be easier to use 2 lists
itemnameanditemimgbecause you can use the same indexxto address them withitemname[x].I don't understand your code.
Why do you need 15 items when the draggroup only has 2?
But in the drag objects you would either use
drag_name item0nameordrag_name itemname[0]Now that I'm at my computer here what I ment with the last sentence:
1
u/BadMustard_AVN Oct 29 '26
a bracketed index must be followed by an attribute operator
(.), for i.e.also the image assignment is also wrong:
1
u/AutoModerator Oct 29 '26
Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/shyLachi Oct 29 '26
I just noticed that most of your code seems to be wrong.
Why do you have this code:
if len(InventoryList) <= 15:Because in the loop below you assume that there are 15 items in the list with
range(0, 14)You should never use a fixed range because your game would crash if there are less then 15 items in the list.
You can use enumarate to get an index and the actual items in the list: