2D array ( table ) problem

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
tetsuken
Prole
Posts: 13
Joined: Sat May 25, 2013 10:42 pm

2D array ( table ) problem

Post 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
tetsuken
Prole
Posts: 13
Joined: Sat May 25, 2013 10:42 pm

Re: 2D array ( table ) problem

Post by tetsuken »

A think i solved the problem ty community.

The solution is change row = {} by level[y] = {} , i think is this ty all
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: 2D array ( table ) problem

Post 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]]
tetsuken
Prole
Posts: 13
Joined: Sat May 25, 2013 10:42 pm

Re: 2D array ( table ) problem

Post 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
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests