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.
if not backpack.inventory:
text "Backpack Empty"
else:
text "Backpack Contents:"
for i in range(len(backpack.inventory)):
$ temp = backpack.inventory[i]
text "[temp]"
textbutton ("Add Poison") action Function(backpack.add_item, item_poison)
textbutton ("Add Potion") action Function(backpack.add_item, item_potion)
I'm kind of stuck here. I just wanted it to display text (for now) for the item that is in the backpack.
Last edited by Avo on Sun Jun 24, 2018 2:49 am, edited 1 time in total.
for item in backpack.inventory:
text "[item.item]"
The way for loop in python works is, it iterates over a list and put the content into your iterator variable. So the above code just loops through your inventory, and for each run of the loop, item becomes the next item. Doing for i in range(len(backpack.inventory)) is actually creating a list with the range function, creating a list of numbers from 0 to (length of your inventory - 1), then iterate over the list of numbers. It's wasteful and unnecessary when you're already using a list
Thank you so much Kivik! I was making it way too difficult with the range(len stuff, you're right. I was using backpack.inventory before but it was giving me the same junk as before, I didn't try the item.item.