So as my complex development attempt didnt go as smoothly last time i decide to use a template from the cookbook for a inventory system this time (viewtopic.php?f=51&t=65379 bt HiddenLife) which worked fine on a surface level but i now ran to several small issue.
The aim is to create consummable that will affect my stat system, but the right way to do it elude me, i try to follow and adapt the one from Elaine (https://www.youtube.com/watch?v=leEiOzuVpTc) but was'nt able to as it's lost into a more complex system.
So once more i'm humbly asking for help, moreso as this thing is python heavy and i still really struggle to see incoherences in it.
So much so in fact that the following code i was planned to submit for this topic has a error i cant fix, so i'll still post it but beware that it has an error.
But for what i need help with is this :
1: the "backpack" reset at each game reboot and does not update between save (ex i have one book, i load a save prior having it and it's still here) so i need a fix for that
(writing a default backpack = () cause a error as it's already define with another line, see code provided), i'm sure it's once more a easy fix i just cant seem to find it.
2: i want that the item in the screen ''backpack" to be interactable and be remove after use (there is a rem_item propmt already in the script but i dont know how to use it)
i'm not too attached to this script so it can be heavy edited and simplifyed if needed, i'll just need it to be compatible with a shop screen down the line but i dont think that will be a issue.
anyway there is what should be the standalone script for testing purpose, but yeah with an error
Code: Select all
##inventory test
image intro = Solid("#6c77a8")
# Inventory script
init -5 python:
class Item(object):
def __init__(self, name):
self.name = name
class InvItem(object):
def __init__(self, item, amount):
self.item = item
self.amount = amount
class Container(object):
def __init__(self):
self.inventory = []
def finditem(self, item):
return(self.inventory[[i.item for i in self.inventory].index(item)])
def has_item(self, item, amount=1):
if item in [i.item for i in self.inventory]:
if self.finditem(item).amount >= amount:
return(self.finditem(item).amount)
else:
return(False)
else:
return(False)
def add_item(self, item, amount=1):
if item in [i.item for i in self.inventory]:
self.finditem(item).amount += amount
else:
self.inventory.append(InvItem(item, amount))
return('success')
def rem_item(self, item, amount=1):
if self.has_item(item):
if self.finditem(item).amount > amount:
self.finditem(item).amount -= amount
return('more left')
elif self.finditem(item).amount == amount:
self.finditem(item).amount -= amount
self.inventory.pop(self.inventory.index(self.finditem(item)))
return('gone')
elif self.finditem(item).amount < amount:
return('not enough')
else:
return('item not found')
#default value
init 0:
$ backpack = Container()
$ money = False
default academics = 15 #value to affect
default book = 0
#item
$ book = Item("book", 1)
#test loop
label start:
scene intro
"test consummable and inventory.
Objective: working inventory screen and consummable effect"
call screen test
screen test:
textbutton _("book") action Jump ("book") xpos 0.5 ypos 0.5
textbutton _("inventory") action Show("backpack") xpos 0.5 ypos 0.55
label book:
$ backpack.add_item("book", 1)
call screen test
#Inventory Screen
screen backpack:
tag inventory
zorder 1000
modal True
hbox:
xalign 0.5
yalign 0.05
spacing 10
side "tl":
area (465, 109, 1, 1)
grid 10 100:
spacing 1
allow_underfull True
for i in backpack.inventory:
vbox:
hbox:
text str(i.amount) size 20
text i.item.name size 15
textbutton _("back"):
action [Hide("backpack"), Show("test")]
As Always, thanks in advance for any help and pointer. it's fortunatly my last script heavy stuff.