Ren'Py [Solved]I'm getting this error using Inventory Screen

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,464
3,410
500


I'm getting this error while using $ inventory.drop(sex_licence)

Code:
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 32, in script
    $ inventory.drop(sex_licence)
  File "game/script.rpy", line 32, in <module>
    $ inventory.drop(sex_licence)
      ~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "game/class.rpy", line 172, in drop
    self.items.remove(item)
    ~~~~~~~~~~~~~~~~~^^^^^^
ValueError: list.remove(x): x not in list

-- Full Traceback ------------------------------------------------------------

Traceback (most recent call last):
  File "game/script.rpy", line 32, in script
    $ inventory.drop(sex_licence)
  File "renpy/ast.py", line 1187, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "renpy/python.py", line 1260, in py_exec_bytecode
    exec(bytecode, globals, locals)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "game/script.rpy", line 32, in <module>
    $ inventory.drop(sex_licence)
      ~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "game/class.rpy", line 172, in drop
    self.items.remove(item)
    ~~~~~~~~~~~~~~~~~^^^^^^
  File "renpy/revertable.py", line 81, in do_mutation
    return method(self, *args, **kwargs)
           ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
ValueError: list.remove(x): x not in list

Windows-11-10.0.26100-SP0 AMD64
Ren'Py 8.4.0.25071206
Nude Town alpha 0.001
Thu Aug 21 08:33:01 2025
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
3,439
6,607
707
So... when it says this:

Code:
list.remove(x): x not in list
I would probably guess that means x is not in the list.

i.e. sex_license is not in the inventory.

1. did the player get to the point in the game without ever getting that item in their inventory in the first place?
2. or is the thing in the list actually "sex_license" not sex_license (without the quotes)?

BTW your inventory class should probably check if the item that is being asked to drop is actually in the list before attempting to remove it.
 
  • Like
Reactions: papel

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,464
3,410
500
here some screenshots with and without the sex_license

it working but the drop item

1755783528994.png
1755783566638.png
 

Winterfire

Conversation Conqueror
Respected User
Game Developer
Sep 27, 2018
6,523
9,365
800
That's so outdated and basic, without even looking at it, I can guess it's using a lot of outdated and slow methods. Why would you refer to that, and not something as basic but recent/explained such as:


Or something more complex/better done yet recent like this:

or many more which you can find on google/itch
 
  • Like
Reactions: rayminator

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,464
3,410
500
That's so outdated and basic, without even looking at it, I can guess it's using a lot of outdated and slow methods. Why would you refer to that, and not something as basic but recent/explained such as:


Or something more complex/better done yet recent like this:

or many more which you can find on google/itch
i am now using Enhanced Renpy Inventory and it's working fine
 
  • Like
Reactions: Winterfire

papel

Active Member
Game Developer
Sep 2, 2018
601
826
152
In situations like that, it's a good thing to experiment printing the list and the object being passed in the function, so you can compare and check whether it's actually attempting to remove the right thing.
print(self.items)
print(item)
 
  • Like
Reactions: osanaiko

rayminator

Engaged Member
Respected User
Sep 26, 2018
3,464
3,410
500
In situations like that, it's a good thing to experiment printing the list and the object being passed in the function, so you can compare and check whether it's actually attempting to remove the right thing.
print(self.items)
print(item)
thanks for the help but it solved now
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
12,935
21,517
1,026
I noticed that you solved the issue, but as reference for future readers who wouldn't have the option to switch to an alternate code:

Code:
  File "game/script.rpy", line 32, in <module>
    $ inventory.drop(sex_licence)
      ~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "game/class.rpy", line 172, in drop
    self.items.remove(item)
    ~~~~~~~~~~~~~~~~~^^^^^^
ValueError: list.remove(x): x not in list
A good practice, is to never blindly remove an entry from a list, set or dict. Always validate first if the entry is in it.

So, the direct solution to this issue would have been to edit the drop method to looks likes this:
Code:
    if item in self.items:
        self.items.remove( item )
If the "item" is in the list, it will be removed. And if it isn't, nothing will happen, what isn't a problem since it will lead to the same result, do so "item" isn't in the list.
 

Mattock

Member
May 27, 2018
135
127
73
sorry for the smartypants...but as "reference for future readers" please note the:
-more complicted
-less understandable for new coders
-but...the python way to do it:
Code:
try:
    self.items.remove( item )
except:
    pass
for more details see:
*ducks*, sorry! sorry;)
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Donor
Respected User
Jun 10, 2017
12,935
21,517
1,026
for more details see:
*ducks*, sorry! sorry;)
And here come the reason why I still hate Python despite using it a lot ;)

Making exceptions be the rule is [I'll not even say it :D]. Be nice with your players, show them that you care about their wellbeing.