[Solved?] ValueError: list.remove(x): x not in list

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
User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

[Solved?] ValueError: list.remove(x): x not in list

#1 Post by Imperf3kt »

This one has me confused.
I am expanding the functionality of my RPS game and have come across this not always reproducible bug that I just don't understand.


I first came across this bug when I noticed that the quick menu stays on screen when it shouldn't if a player shows certain screens.
So to begin with, here's the error I am receiving.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 208, in <module>
ValueError: list.remove(x): x not in list

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

Full traceback:
  File "script.rpyc", line 208, in script
  File "/data/user/0/com.imperf3ktsoft.rpsv2/files/renpy/ast.py", line 881, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "/data/user/0/com.imperf3ktsoft.rpsv2/files/renpy/python.py", line 1913, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 208, in <module>
  File "/data/user/0/com.imperf3ktsoft.rpsv2/files/renpy/python.py", line 713, in do_mutation
    return method(self, *args, **kwargs)
ValueError: list.remove(x): x not in list

And the related files. I named them .txt so I could read them on my phone, although it probably wasn't necessary.
The files are all just standard .rpy files.
rps.txt
(4.76 KiB) Downloaded 14 times
screens.txt
(39.81 KiB) Downloaded 17 times
script.txt
(8.94 KiB) Downloaded 14 times
And here's the apk
https://mega.nz/#!Bd0nFCQL!IfVhdZeZKIuk ... fsvPdbbGKo

To get the error, a certain sequence of events must be followed.
First, I need to make a selection, "rock", "paper" or "scissors"
This should jump to the results label after evaluating the result as win, tie or lose.
If I press the hint button here, this will jump to the hintacc label.
Pressing return will jump me to label hinted. After this, pressing any of the buttons in screen rps_selection, triggers the error. It doesn't always happen though, sometimes it takes two or three tries.

I'm a bit confused and not sure how this works right now (I wrote it but don't understand it lol)

Can anyone point out why this is happening and if there's a better way to handle this.
I also feel theres a better way to handle the function of hint40, hint60 and hint80 labels.
Last edited by Imperf3kt on Wed Mar 27, 2019 9:25 am, edited 2 times in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

philat
Eileen-Class Veteran
Posts: 1909
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: ValueError: list.remove(x): x not in list (Android)

#2 Post by philat »

I mean... what it says on the can. $ hintlist.remove(result) in line 208 is throwing an error, because whatever the result is is not in hintlist. I haven't bothered to go through everything, because it's really long, but there's a kink in the logic somewhere. *shrug*

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: ValueError: list.remove(x): x not in list (Android)

#3 Post by Imperf3kt »

Yes I understand that. I'm just not sure why there's nothing in the list, as far as I can see, there should be something in the list.

I'll have to check later and see if the same error occurs on my PC, and if it does I'll have to dig deeper.

I agree everything is a bit of a mess at the moment, there's several things still present that I removed but never tidied up.




Edit:

After looking again, I think I've figured it out, maybe.
I append 'result' to the list in label rps_select.
Then I remove 'result' from list during the 'results' label, and then check the players selection against 'result' (not from the list) after which I jump back to label rps_select where I reevaluate 'result' and once more append it to the list to begin a new round.

I think, maybe it is removing more than just the first item from the list.

I will try using 0 instead of result when I can.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: ValueError: list.remove(x): x not in list (Android)

#4 Post by Remix »

If it's trying to remove something and the something isn't there, it doesn't need to actually run, so you could just wrap it in a conditional:

if result in hintlist: hintlist.remove( result )

So saying, that does not resolve the logic issue of trying to remove something that isn't there, even if it would likely cure the error
Frameworks & Scriptlets:

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3791
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: ValueError: list.remove(x): x not in list

#5 Post by Imperf3kt »

Still getting this error and I can see no reason for why.
I've traced my logic to all possible extents, and am 100% sure the item is in the list at the moment it fails.

If I click ignore or rollback, the game proceeds just fine, it has no problems at all and functions as expected.

Interestingly, after changing my quick menu to only show while the say screen is showing the issue no longer appears.

Code: Select all

screen quick_menu():

    ## Ensure this appears on top of other screens.
    zorder 100

    if quick_menu and renpy.get_screen("say"):
    
I since made some other minor tweaks anyway.
The button to choose a hint shouldn't appear during results anyway, so now it doesn't. It should be impossible to stumble across this issue by accident now, even if it still persists.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

Post Reply

Who is online

Users browsing this forum: No registered users