Page 1 of 1

Problem with tables

Posted: Fri Nov 09, 2012 8:54 am
by DB
Hey guys,

I got a small problem with retrieving information out of a 2d table, anyone mind giving me a hand? Basically what I'm trying to do is retrieve information out of a table for cutting up my spritesheet with quads.

Code:


Code: Select all

local tilequads=
{
	{40,0},
	{40,0},
	{80,0}
}

for i = 1, #tilequads do
		local info = #tilequads[i]
		--print(info[1])
		--tile[i] = love.graphics.newQuad(info[1], info[2], Grid.tilewidth, Grid.tileheight, tilesetW, tilesetH)
end
The solution to my problem probably is very easy but some help would be appreciated :) Thanks in advance.

Re: Problem with tables

Posted: Fri Nov 09, 2012 10:32 am
by micha
Just remove the #-sign before tilequads. In your version "info" will be the number 2 (length of the entries) and not the content of your table.

Should work like this:

Code: Select all

for i = 1, #tilequads do
      local info = tilequads[i]
      --print(info[1])
      --tile[i] = love.graphics.newQuad(info[1], info[2], Grid.tilewidth, Grid.tileheight, tilesetW, tilesetH)
end