从表格调用 x, y

Calling from tables to x, y

我又在做一些 lua (Love2D),我想调用一些表格作为我的 love.graphics.rectangle 的 X/Y 坐标。我的代码是这样的。

function love.load()
 x=0
 y=0
 x2={}
 y2={}
end
function love.update(dt)
 if love.keyboard.isDown(" ") then
  table.insert(x2, x)
  table.insert(y2, y)
 end
end
function love.draw()
 for i,v in pairs(--What should I do here?--) do
  love.graphics.rectangle("fill", --How would I make these coordinates match the ones in the table?--)
 end
end

我的代码不是这样的,但它只是说明了我的目的。

love.graphics.rectangle("fill", --How would I make these coordinates match the ones in the table?--)

love.graphics.rectangle("fill", 0, 0)

因为您总是在 table 中插入 0,所以就可以了。

你的代码太做作了,几乎不可能说出你在问什么。您要解决的问题是什么?具体为什么要把x,y坐标放到一个table?如果您的目标是从各自的 table 中读取最后插入的值,那么请执行以下操作:

love.graphics.rectangle("fill", x2[#x2], y2[#y2])

# 是长度运算符,因此 t[#t] 将获取 table t.

中的最后一个元素

请注意,每当 space 柱向下时插入 table 将很快创建一个巨大的 table。