Skip to content
Advertisement

How do you prevent “unhashable type ‘list'”?

So, I was making a simple 2D game in pygame, and was making the map (following a tutorial video, don’t judge me, I’m new to pygame) and using replit.com, and that error showed up in the console.

here’s my code for it:

JavaScript

if anyone has any suggestions for changing my code, please say, and I am sticking with replit.com

Advertisement

Answer

You’re pretty much correct already. I’m just guessing at how your code is supposed to work, but using a python dictionary for the tile colours with integer-variables as keys is what’s causing the issue.

If you change your tile keys to a letter:

JavaScript

And then in your map, use letters too:

JavaScript

It works pretty much perfectly:

screen shot

Full code:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement