Code: Select all
#USE ITEM FOUND (INV/CONT)
elif self.name == "gun" and obj_gun in inventory.items and found_session:
inventory.drop(self)
container_found.add(self)
elif self.name == "gun" and obj_gun in container_found.items and inventory_havespace and found_session:
inventory.add(self)
container_found.drop(self)
Because now I want the player to be able to have more than one "gun".
The matter is when there is more than one item "gun" in container, you can click and add the first one to your inventory but when you click the second one the "gun" you just took is drop back into the container because of my conditions.
I want to be able to distinguish this two item without having to change there name (I don't want "gunA", "gun2", etc) so I have try this :
(changing obj_gun in container_found and obj_gun in inventory by self in container_found and self in inventory)
Code: Select all
#USE ITEM FOUND (INV/CONT)
elif self.name == "gun" and obj_gun in inventory.items and found_session:
inventory.drop(self)
container_found.add(self)
elif self.name == "gun" and obj_gun in container_found.items and inventory_havespace and found_session:
inventory.add(self)
container_found.drop(self)
Do someone have an idea to how should I proceed ? I am in the fog when it comes to Python synthax so I don't really know how to do it.
This is the complete code for the inventory :
Code: Select all
$ obj_gun = Item("Gun", image="gui/item_icon_gun.png")
Code: Select all
init -1 python:
import renpy.store as store
import renpy.exports as renpy # Needed so Ren'Py properly handles rollback with classes
from operator import attrgetter # Needed this for sorting items
item = None
class Item(store.object):
def __init__(self, name, image=""):
self.name = name
self.image=image # image file to use for this item
def use(self):
#USE ITEM which is in the INVENTORY
if self.name == "Tools" and obj_tool_is_dropable and obj_tool in inventory.items:
container.add(self)
inventory.drop(self)
elif self.name == "Ducktape" and obj_ducktape_is_dropable and obj_ducktape in inventory.items:
container.add(self)
inventory.drop(self)
elif self.name == "Teddybear" and obj_teddybear_is_dropable and obj_teddybear in inventory.items:
container.add(self)
inventory.drop(self)
elif self.name == "Bassin" and obj_bassin_is_dropable and obj_bassin in inventory.items:
container.add(self)
inventory.drop(self)
elif self.name == "Soap" and obj_soap_is_dropable and obj_soap in inventory.items:
container.add(self)
inventory.drop(self)
elif self.name == "Sponge" and obj_sponge_is_dropable and obj_sponge in inventory.items:
container.add(self)
inventory.drop(self)
elif self.name == "Towel" and obj_towel_is_dropable and obj_towel in inventory.items:
container.add(self)
inventory.drop(self)
#USE ITEM which is in the CONTAINER
elif self.name == "Tools" and obj_tool in container.items and inventory_havespace:
inventory.add(self)
container.drop(self)
elif self.name == "Ducktape" and obj_ducktape in container.items and inventory_havespace:
inventory.add(self)
container.drop(self)
elif self.name == "Teddybear" and obj_teddybear in container.items and inventory_havespace:
inventory.add(self)
container.drop(self)
#USE ITEM FOUND (INV/CONT)
elif self.name == "gun" and self in inventory.items and found_session:
inventory.drop(self)
container_found.add(self)
elif self.name == "gun" and self in container_found.items and inventory_havespace and found_session:
inventory.add(self)
container_found.drop(self)
class Inventory(store.object):
def __init__(self):
self.items = []
def add(self, item): # we could also add conditions that check the space in the inventory
self.items.append(item)
if len(inventory.items)> 3 :
store.inventory_havespace = False
else:
store.inventory_havespace = True
def drop(self, item):
self.items.remove(item)
if len(inventory.items)> 3 :
store.inventory_havespace = False
else:
store.inventory_havespace = True
def item_use():
item.use()
class Container(store.object):
def __init__(self):
self.items = []
def add(self, item):
self.items.append(item)
def drop(self, item):
self.items.remove(item)