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.
I seem to recall that saving values in arrays are not as robust as in individual variables.
You could try creating a temporary variable, incrementing that, then storing into the array.
You can't do 'items.nbr', since items is a list and nbr is an attribute of Item. You'll have to access the item in the list first. For example:
(This snippet assumes that you have instantiated the Inventory class as "inv")
[...]
def buy(self, item):
if self.money >= item.cost:
self.money -= item.cost
self.items.append(item)
self.items[-1].nbr += 1 # This accesses the last element of the list
return True
else:
return False
[...]
However, this is a bit useless since if you already have an item in your list, it won't add the to the nbr of the existing item, it'll just add another item. You could solve that like this:
[...]
def buy(self, item):
if self.money >= item.cost:
self.money -= item.cost
if item in self.items:
self.items[self.items.index(item)].nbr += 1 # The item is already in the list, so find it and increase the nbr.
else:
self.items.append(item)
self.items[-1].nbr = 1 # This accesses the last element of the list
return True
else:
return False
[...]