Page 1 of 1

2D array ( table ) problem

Posted: Sun Jan 12, 2014 2:22 am
by tetsuken
Hello again community,
I'm with some problems to define a value on a table inside a table. I'm using the command:

Code: Select all

level[1][row[1]] = 3
to try define especifically the 1st position of the row table inside the level table but what i'm getting is all the row elements becoming = 3.
This is for procedural level assembly on my dungeon game. i will post the code is someone could help i appreciate.

Code: Select all


function love.update(dt)
    
	level[1][row[1]] = 3

	
end
 
function love.draw()
	--love.graphics.draw(Tileset, tile[1], 100, 100)  
	
	createlevel()
	
end
 
function love.keyreleased(key)
    if key == "escape" then
        love.event.push("q")   -- actually causes the app to quit
    end
    if (key == "right") or (key == "left") then
        p:stop()
    end
end

function createlevel() 
	
	for y = 1, #level do
		for x = 1, #level[y] do
			t = level[y][row[x]]
			love.graphics.draw(Tileset, tile[t], x*32, y*32)
		end
    end
	
end

Re: 2D array ( table ) problem

Posted: Sun Jan 12, 2014 2:39 am
by tetsuken
A think i solved the problem ty community.

The solution is change row = {} by level[y] = {} , i think is this ty all

Re: 2D array ( table ) problem

Posted: Sun Jan 12, 2014 10:05 am
by micha
Could you explain what the table "row" is for?

Usually the access to a two dimensional array looks like this:

Code: Select all

array[x][y]
and not

Code: Select all

array[x][row[y]]

Re: 2D array ( table ) problem

Posted: Sun Jan 12, 2014 9:19 pm
by tetsuken
Ty Micha, i realised that, but before i was using a row table inside of level table, after some google research i realised i should make the level[x] a table it self.

Now my problem is another like overllaping rooms for my dungeon, but this will be another topic.

Ty very much