"The variable inventory.items[0].clicked does not exist"

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
gabowave
Newbie
Posts: 10
Joined: Sat Jul 08, 2023 4:15 pm
Contact:

"The variable inventory.items[0].clicked does not exist"

#1 Post by gabowave »

Hello all, I am trying to toggle a variable from False to True in an imagebutton action with the use of the action ToggleVariable("inventory.items[0].clicked) and it doesn't seem to be working. I am hoping to see if I can find a solution to this or potentially a workaround but so far no dice.

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
And here is my Code for that particular area. Warning, its not pretty. I am not a good programmer.

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
Here is the code for the classes I'm making use of:

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...")
Any Ideas on how to improve/solution/workarounds would be great. thank you so much.

enaielei
Veteran
Posts: 293
Joined: Fri Sep 17, 2021 2:09 am
Organization: enaielei
Tumblr: enaielei
Deviantart: enaielei
Github: enaielei
Skype: enaielei
Soundcloud: enaielei
itch: enaielei
Discord: enaielei#7487
Contact:

Re: "The variable inventory.items[0].clicked does not exist"

#2 Post by enaielei »

ToggleField or SetField

Code: Select all

ToggleField(inventory.items[0], "clicked", True, False)
SetField(inventory.items[0], "clicked", not inventory.items[0].clicked)

gabowave
Newbie
Posts: 10
Joined: Sat Jul 08, 2023 4:15 pm
Contact:

Re: "The variable inventory.items[0].clicked does not exist"

#3 Post by gabowave »

enaielei wrote: Sun Jul 09, 2023 12:02 am ToggleField or SetField

Code: Select all

ToggleField(inventory.items[0], "clicked", True, False)
SetField(inventory.items[0], "clicked", not inventory.items[0].clicked)
Thank you so much!

Post Reply

Who is online

Users browsing this forum: VeritasLex