Reputation: 47
I am again doing some lua (Love2D), and I want to call upon some tables as X/Y coordinates for my love.graphics.rectangle
s. My code is like this.
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
My code isn't like this, but it just shows what I'm going for.
Upvotes: 0
Views: 106
Reputation: 29021
love.graphics.rectangle("fill", --How would I make these coordinates match the ones in the table?--)
love.graphics.rectangle("fill", 0, 0)
Since you're always inserting 0 into the tables, that'll do that job.
Your code is so contrived it's almost impossible to tell what you're asking. What is the problem you're trying to solve? Specifically why do you want to put the x, y coordinates into a table? If your goal is to read the last inserted values from the respective tables, then do this:
love.graphics.rectangle("fill", x2[#x2], y2[#y2])
#
is length operator, so t[#t]
will get the last element in the table t
.
Note that inserting into a table whenever the space bar is down is going to create a huge table very quickly.
Upvotes: 1