My intention with this code is to make an inventory system that when an inventory slot is clicked the item is selected in such way that I can use an if statement to use said specific Item.
The reason my item is inside of a list is because the slots are ordered in lists in order to keep them ordered.
Here is my traceback:
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/reusable.rpy", line 94, in script
$ renpy.pause(hard=True)
File "game/reusable.rpy", line 94, in <module>
$ renpy.pause(hard=True)
File "renpy/common/00action_data.rpy", line 217, in __call__
value = _get_field(self.object, self.field, self.kind)
File "renpy/common/00action_data.rpy", line 39, in _get_field
raise NameError("The {} {} does not exist.".format(kind, name))
NameError: The variable inventory.items[0].clicked does not exist.
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/reusable.rpy", line 94, in script
$ renpy.pause(hard=True)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/ast.py", line 1138, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/python.py", line 1122, in py_exec_bytecode
exec(bytecode, globals, locals)
File "game/reusable.rpy", line 94, in <module>
$ renpy.pause(hard=True)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/exports.py", line 1637, in pause
rv = renpy.ui.interact(mouse='pause', type='pause', roll_forward=roll_forward, pause=delay, pause_modal=modal)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/ui.py", line 299, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/core.py", line 3579, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, pause_modal=pause_modal, **kwargs) # type: ignore
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/core.py", line 4540, in interact_core
rv = root_widget.event(ev, x, y, 0)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/layout.py", line 1177, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/layout.py", line 1177, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/layout.py", line 1177, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/screen.py", line 770, in event
rv = self.child.event(ev, x, y, st)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/layout.py", line 1177, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/behavior.py", line 1138, in event
return handle_click(self.clicked)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/behavior.py", line 1071, in handle_click
rv = run(action)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/behavior.py", line 368, in run
new_rv = run(i, *args, **kwargs)
File "/Users/jose/Documents/renpy-8.1.1-sdk/renpy/display/behavior.py", line 375, in run
return action(*args, **kwargs)
File "renpy/common/00action_data.rpy", line 217, in __call__
value = _get_field(self.object, self.field, self.kind)
File "renpy/common/00action_data.rpy", line 39, in _get_field
raise NameError("The {} {} does not exist.".format(kind, name))
NameError: The variable inventory.items[0].clicked does not exist.
macOS-14.0-arm64-arm-64bit arm64
Ren'Py 8.1.1.23060707
Rockwood 0.18v "Startup[WIP]"
Sat Jul 8 23:32:57 2023
Code: Select all
imagebutton:
xoffset -30
yoffset -13
idle "images/Screens/MainUI/Inventory/Slot1_idle.png"
hover "images/Screens/MainUI/Inventory/Slot1_hover.png"
selected_idle "images/Screens/MainUI/Inventory/Slot1_hover.png"
selected_hover "images/Screens/MainUI/Inventory/Slot1_hover.png"
selected slot1selected
sensitive slot1sensitive
action [ToggleVariable("slot1selected"), ToggleVariable("inventory.items[0].clicked"), ToggleVariable("itemselected"), ToggleVariable("slot2sensitive"), ToggleVariable("slot3sensitive"), ToggleVariable("slot4sensitive"), ToggleVariable("slot5sensitive"), ToggleVariable("slot6sensitive"), SelectedIf(slot1selected == True)]
focus_mask True
Code: Select all
init python:
class Inventory():
def __init__(self, items=[], total=0):
self.total = total
self.items = items
def add_item(self, items):
if len(self.items) < 6:
self.items.append(items)
self.total += 1
n ("You've recieved an item")
else:
p ('Damn lemme put this in ma bag')
p ("This jawn don fit.")
def list_items(self):
if len(self.items) < 1:
p ("I don't have anything on me.")
else:
p ("I have...")
for item in self.items:
p("{}, {} and I have {} of dem Jawns".format(item.name, item.description, item.ammount))
class Items():
def __init__(self, ID=0, image=",", name='-', description='/', clicked=False):
self.ID = ID
self.name = name
self.description = description
self.ammount = 1
self.image = image
self.clicked = clicked
def add(self, num):
self.ammount += num
n ("Item Quantity Updated")
def remove(self, num):
self.ammount -= num
n ("Item Quantity Updated")
default inventory = Inventory([], 0)
define obj1 = Items(1, "images/Screens/MainUI/InventoryIcons/id01.png", "Bathroom Keys", "This key should open the bathroom door...")