Code: Select all
for item in inventory.list_of_items:
textbutton ("Use") action inventory.delete_item(item)Code: Select all
if(deleteThis!=None):
inventory.list_of_items.remove(deleteThis)
for item in list_of_items:
textbutton ("Use") action SetVariable("deleteThis", item)There's a bit of code that checks if the inventory is empty, and if so, writes "(Inventory empty)". However when everything has been deleted, I only get "(Inventory empty" - the closing bracket is missing for some reason. The code goes like this:
In the Inventory class, there are two functions:
Code: Select all
# Get a list of all unique items
def getUniqueList(self):
uniqueSet = Set(item for item in self.list_of_items)
return [item for item in uniqueSet]
# Get the number of times an item appears in the inventory
def getUniqueCount(self):
uniqueSet = Set(item for item in self.list_of_items)
return [self.list_of_items.count(item) for item in uniqueSet]Code: Select all
if(inventory.list_of_items): # Inventory is not empty
# Remove item
if(deleteThis!=None):
inventory.list_of_items.remove(deleteThis)
$ uniqueList = inv.getUniqueList()
$ countList = inv.getUniqueCount()
for i, item in enumerate(uniqueList):
$ currCount = countList[i]
textbutton ("[item.name] (x[currCount])") action SetVariable("deleteThis", item)
else:
text "(Inventory empty)"
