I'am working on this portion of python code :
Code: Select all
def use(self, item):
if item.usable and item in self.items:
self.items.remove(item)
print("", "Item used!")
else:
print("", "Item can't be used!")
I just want to check a condition in this python code, BUT I don't want to do it inside this fonction and I don't know how to get out this fonction to call a label or an other fonction.
WHAT I'M TRING TO DO (LONG VERSION) :
I'am using different items and I want a different effect for each of them when they are used.
But I have a lot of items, so I don't want to incorporate the "what_item_is_used" inside this fonction.
I prefer to go back to renpy code because I'am more at my ease with it that I am with Python.
So it would be great if someone can show me how to go out this fonction and check which items in a renpy label.
Something like
Code: Select all
def use(self, item):
if item.usable and item in self.items:
self.items.remove(item)
jump label_what_item_is_used
print("", "Item used!")
else:
print("", "Item can't be used!")
Code: Select all
label label_what_item_is_used:
if self.items == apple:
You eat an apple.
Hunger - 15
if self.items == water:
You drink water.
Thrist - 15
Just for let you know, this is the other part of the code relevant to this.
Code: Select all
class Item(store.object):
def __init__(self, name, image="", trashable=True, usable=True):
self.name=name
self.image=image
self.trashable = trashable
self.usable= usable
class Inventory(store.object):
def __init__(self, spaces = 4):
self.items = []
self.spaces = spaces
def add(self, item):
if self.has_space():
self.items.append(item)
return True
else:
return False
def trash(self, item):
if item.trashable and item in self.items:
self.items.remove(item)
print("", "Item is trashed!")
else:
print("", "Item can't be trashed!")
def drop(self, item):
if item in self.items:
self.items.remove(item)
print("", "Item dropped!")
else:
print("", "Item can't be dropped!")
def use(self, item):
if item.usable and item in self.items:
self.items.remove(item)
print("", "Item used!")
else:
print("", "Item can't be used!")
Code: Select all
items = {
"Null_Item": Item("Null_Item", image="gui/item_icon_tools.png"),
# Quest_Item
"Revolver": Item("Revolver", image="gui/item_icon_weapon_revolver.png", trashable=False, usable=False),
"Tools": Item("Tools", image="gui/item_icon_tools.png", trashable=False, usable=False),
"Ducktape": Item("Ducktape", image="gui/item_icon_ducktape.png", trashable=False, usable=False),
"Sponge": Item("Sponge", image="gui/item_icon_sponge.png", trashable=True, usable=False),
# Generic_Item
"FoodFruit1": Item("FoodFruit1", image="gui/item_icon_foodfruit_1.png", trashable=True, usable=True),
"WaterBottleEmpty": Item("WaterBottleEmpty", image="gui/item_icon_waterbottle_empty.png", trashable=True, usable=True),
"Rice": Item("Rice", image="gui/item_icon_rice.png", trashable=True, usable=True),
"Wood": Item("Wood", image="gui/item_icon_wood.png", trashable=True, usable=True),
}