I was making a game with pygame where you could pick up tiles and throw them. I ran into an issue where if I threw a block and tried to pick it back up, I get an error. I know what the issue is, but I don't know how to fix it
IndexError: pop index out of range This gets the index of the block that I am going to pick up:
# Checks if player is touching a block and pressing down arrow to remove a block and add a block above the player's head
if collisions["left"] and pick_block or collisions["right"] and pick_block:
for tile in xcollisions:
if pick_block_count == 0:
if not holding_block:
tpb = tile
tile_pops.append(tile_rects.index(tile))
holding_block = True
pick_block_count += 1
else:
xcollisions = 0
# Removes the tile that is picked up
for tile in tile_pops:
tile_rects.pop(tile)
drectp = display_rects.pop(tile)
That removes the block. I know what the problem is, but I don't know how to fix it
Here is my full code: https://pastebin.com/3eszkgkK Here is the map I use: https://pastebin.com/ftWL4mVD For the textures you can use any 16x16 texture