【问题标题】:love2D error: unpack expected table got userdatalove2D 错误:解压预期表得到用户数据
【发布时间】:2017-05-25 05:04:11
【问题描述】:

当我尝试解包此表以调用图像时,程序返回错误“解包的参数错误(表预期得到用户数据)”

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

这是我正在使用的表

  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

这是我尝试打开表格的地方

【问题讨论】:

  • love.graphics.newImage() 返回用户数据。为什么您希望加载的图像是一张表格?

标签: lua love2d lua-userdata


【解决方案1】:

如果要解压表格纹理:

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

你必须写unpack(textures),而不是unpack(textures[map[mapX][mapY]),因为textures[map[mapX][mapY]显然不是表textures,而是它的子元素之一,它恰好是userdata类型。

【讨论】:

    猜你喜欢
    • 2017-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 2018-07-05
    • 1970-01-01
    • 2020-06-22
    • 1970-01-01
    相关资源
    最近更新 更多