- Dec 18, 2019
- 21
- 1
Good morning,
I have a problem with the inventory system regarding the energy level.
The code itself works perfectly but i want to add in the removeItem paragraph that the energy level goes up when you drink an energydrink. In renpy i would just add :
if player_energy <= 100:
$ player_energy += 10
What do i have to do here to make it work?
This is my code for the inventory class :
I have a problem with the inventory system regarding the energy level.
The code itself works perfectly but i want to add in the removeItem paragraph that the energy level goes up when you drink an energydrink. In renpy i would just add :
if player_energy <= 100:
$ player_energy += 10
What do i have to do here to make it work?
This is my code for the inventory class :
init python:
class Item:
def __init__(self, code, name, desc, img = "noimage", value = 0, iType = "item", uses = -1, unique = False):
self.code = code
self.name = name
self.desc = desc
self.img = img
self.value = value
self.iType = iType
self.uses = uses
class Inventory:
def __init__(self, name, money = 0, background = "images/inventory/inventory_panel.png", slots = 40):
self.name = name
self.money = money
self.background = background
self.slots = slots
self.items = []
def addItem(self, item):
if self.freeSlots():
if self.hasItem(item) is not False and item.unique == True:
return False
else:
self.items.append([item, item.uses])
self.items.sort(key=lambda i: i[0].name)
#renpy.notify("New Item!")
return True
else:
return False
return
def hasItem(self, item):
for i in self.items:
if i[0] == item:
return self.items.index(i)
return False
def freeSlots(self):
tmp = self.slots - len(self.items)
if tmp <= 0:
return False
else:
return tmp
def removeItem(self, item):
invIndex = self.hasItem(item)
if invIndex is not False and self.items[invIndex][1] != -1:
if self.items[invIndex][1] > 1:
if self.items[invIndex][0].iType == "energydrink":
self.items[invIndex][1] -= 1
if self.items[invIndex][0].iType == "usable":
self.items[invIndex][1] -= 1
return