1

When I attempt to unpack this table to call on the images, the program returns the error "bad argument to unpack (table expected got userdata)"

textures = {love.graphics.newImage("image.png"),
      love.graphics.newImage("image.png"),
      love.graphics.newImage("image.png"),
      love.graphics.newImage("image.png"),
      }

This is the table I am using

  drawScreenLineTexture[x] = {unpack(textures[map[mapX][mapY]])}
if side == 1 then
  drawScreenLineTexture[x][1] = drawScreenLineTexture[x][1] / 2
  drawScreenLineTexture[x][2] = drawScreenLineTexture[x][2] / 2
  drawScreenLineTexture[x][3] = drawScreenLineTexture[x][3] / 2
end

This is where I attempt to unpack the table

miken32
  • 42,008
  • 16
  • 111
  • 154
Noah Jb
  • 87
  • 6

1 Answers1

2

If you want to unpack the table textures:

textures = {love.graphics.newImage("image.png"),
      love.graphics.newImage("image.png"),
      love.graphics.newImage("image.png"),
      love.graphics.newImage("image.png"),
      }

you have to write unpack(textures), not unpack(textures[map[mapX][mapY]) as textures[map[mapX][mapY] is obviously not the table textures but one of its sub-elements which happes to be of type userdata.

Piglet
  • 27,501
  • 3
  • 20
  • 43