Skip to content
Discussion options

You must be logged in to vote

Hey 👋

That error means block_types is actually an integer, but the code is trying to use it like a list or dict.

For example, this line:

texture = load_texture().get(block_types[selected_block_index])

only works if block_types is something like:

block_types = ["grass", "stone", "dirt"]

so that block_types[selected_block_index] returns a valid item (like "grass").

But since you’re getting:

TypeError: 'int' object is not subscriptable

it means block_types is probably just a number right now — e.g.:

block_types = 3

and numbers can’t be indexed like lists.

Fix:
Make sure block_types is a list, tuple, or dict before that line runs. For example:

block_types = ["grass", "stone", "dirt"]
selec…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Anthony162010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Ask and answer questions about GitHub features and usage Programming Help Discussions around programming languages, open source and software development
3 participants