Follow up now that its the light of day and I'm not half sleep. This again is my inventory code now with correct underscores.
Code: Select all
init -1 python:
class Item(object):
def __init__(self, name, amount=0):
self.name = name
self.amount = amount
class Inv_item(object):
def __init__(self, item, amount=0):
self.item = item
self.amount = amount
class Container(object):
def __init__(self):
self.inventory = ()
def has_item(self, item, amount=1):
if item in [i.item for i in self.inventory]:
if self.inventory[[i.item for i in self.inventory].index(item)].amount >= amount:
return(self.inventory[[i.item for i in self.inventory].index(item)].amount)
else:
return(False)
def find_item(self, item):
return(self.inventory[[i.item for i in self.inventory].index(item)])
def add_item(self, item, amount=1):
self.inventory.append(Inv_item(item, amount))
def remove_item(self, item, amount=1):
if self.has_item(item):
self.find_item(item).amount -= amount
if self.find_item(item).amount <= 0:
self.inventory.pop(self.inventory.index(self.find_item(item)))
default workbag = Container()
default phone = Item("Phone", 1)
And this is my screen code
Code: Select all
screen invdisplay:
vbox:
align (0.0, 0.0)
text "Inventory:"
for Item in workbag:
text ("[item.name]")
And when I launch my game I get
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 28, in script
tc "So this is they story of me, Troy Colby, and the time I tried to do the right thing and still got stuck literally holding the bag."
File "game/screens.rpy", line 1518, in execute
screen invdisplay:
File "game/screens.rpy", line 1518, in execute
screen invdisplay:
File "game/screens.rpy", line 1519, in execute
vbox:
TypeError: 'Container' object is not iterable
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 28, in script
tc "So this is they story of me, Troy Colby, and the time I tried to do the right thing and still got stuck literally holding the bag."
File "/Applications/renpy-6.99.14.3-sdk/renpy/ast.py", line 652, in execute
renpy.exports.say(who, what, interact=self.interact, *args, **kwargs)
File "/Applications/renpy-6.99.14.3-sdk/renpy/exports.py", line 1199, in say
who(what, *args, **kwargs)
File "/Applications/renpy-6.99.14.3-sdk/renpy/character.py", line 1016, in __call__
self.do_display(who, what, cb_args=self.cb_args, **display_args)
File "/Applications/renpy-6.99.14.3-sdk/renpy/character.py", line 817, in do_display
**display_args)
File "/Applications/renpy-6.99.14.3-sdk/renpy/character.py", line 566, in display_say
rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
File "/Applications/renpy-6.99.14.3-sdk/renpy/ui.py", line 287, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/core.py", line 2649, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/core.py", line 3033, in interact_core
root_widget.visit_all(lambda i : i.per_interact())
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/core.py", line 511, in visit_all
d.visit_all(callback)
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/core.py", line 511, in visit_all
d.visit_all(callback)
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/core.py", line 511, in visit_all
d.visit_all(callback)
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/screen.py", line 424, in visit_all
callback(self)
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/core.py", line 3033, in <lambda>
root_widget.visit_all(lambda i : i.per_interact())
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/screen.py", line 434, in per_interact
self.update()
File "/Applications/renpy-6.99.14.3-sdk/renpy/display/screen.py", line 619, in update
self.screen.function(**self.scope)
File "game/screens.rpy", line 1518, in execute
screen invdisplay:
File "game/screens.rpy", line 1518, in execute
screen invdisplay:
File "game/screens.rpy", line 1519, in execute
vbox:
File "/Applications/renpy-6.99.14.3-sdk/renpy/sl2/slast.py", line 1428, in execute
for index, v in enumerate(value):
TypeError: 'Container' object is not iterable
Darwin-16.6.0-x86_64-i386-64bit
Ren'Py 7.0.0.196
Hurricane Like Me 0.1
Wed Jul 4 13:27:04 2018
When I take out the screen code it works perfectly (as in no errors), I can add items to my inventory and everything with no problem. I just can't see what I'm adding which is frustrating.