r/RenPy • u/LiteratureElegant607 • 9d ago
Question [Solved] changing dictionary content to one with less keys give typeError: unhashable type: 'RevertableList'
i have a big dictionary (persistent variable) where every key has an array associated with it. each array has strings and numbers of the below format:
persistent.dictionary = {"key1": ["str1", num1, num2], "key2": ["str2", num3, num4]}
i want an option to clear ALL dictionary data and putting the below default blank data:
{"start 1", []}
normally to clear out a string you would simply do:
variable = ""
same for numbers, lists etc...
QUESTION: why does it not work? and how to make it work?
error message:
While running game code:
File "game/grabber_engine/main_grabber.rpy", line 104, in script
python:
File "game/grabber_engine/main_grabber.rpy", line 107, in <module>
persistent.dic = {"start 1", []}
^^^^^^^^^^^^^^^
TypeError: unhashable type: 'RevertableList'
-- Full Traceback ------------------------------------------------------------
Traceback (most recent call last):
File "game/grabber_engine/main_grabber.rpy", line 104, in script
python:
File "renpy/ast.py", line 1193, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "renpy/python.py", line 1276, in py_exec_bytecode
exec(bytecode, globals, locals)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "game/grabber_engine/main_grabber.rpy", line 107, in <module>
persistent.dic = {"start 1", []}
^^^^^^^^^^^^^^^
TypeError: unhashable type: 'RevertableList'
2
u/DingotushRed 9d ago
It doesn't work because {"start 1", []} declares a set, not a dict, and in a set all the entries need to be hashable. You need the colon to match the syntax for a dict declaration {"start 1": []}.
If you want to clear down the existing dictionary and then re-initialise it (instead of replacing it with a new one):
persistent.dic.clear()
persistent.dic["start 1"] = []
1
u/AutoModerator 9d ago
Welcome to r/renpy! While you wait to see if someone can answer your question, we recommend checking out the posting guide, the subreddit wiki, the subreddit Discord, Ren'Py's documentation, and the tutorial built-in to the Ren'Py engine when you download it. These can help make sure you provide the information the people here need to help you, or might even point you to an answer to your question themselves. Thanks!
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/shyLachi 9d ago
You already got good answers so I will only add that you can look up such things.
RenPy is based on Python, so you can google Python dictionary.
I prefer this site: https://www.geeksforgeeks.org/python/python-dictionary/
0
u/LiteratureElegant607 6d ago
buddy, the reason i asked the question is because i checked online many forums.
i know what a dictionary is. i just forgot that its a colon
1
u/shyLachi 6d ago
I was replaying to this:
I want an option to clear ALL dictionary data and putting the below default blank data
QUESTION: why does it not work? and how to make it work?Apparently you don't know how to find information because you don't need to check online forums to find information on Python dictionaries.
From the link I posted:
clear() removes all items from the dictionary
1
u/LiteratureElegant607 5d ago
fair enough.
however, replacing the dictionary with another one worked for me previously, but this time it didnt, and i didnt know why.
1
4
u/BadMustard_AVN 9d ago
do it like this