Page 1 of 1

Beginner Questions: Drawing with Lua and syntax

Posted: Mon Aug 06, 2012 9:24 pm
by kaizari
Hi, I'm pretty new to Lua and love2d but have used other programming languages (PHP, Javascript and Powershell) for a bit.

I'm planning to programm a little game for practise that is like draw something. I hope to get some more knowledge in a coordinate system and some networking.

I imagined it like this:
Spawn a coordinate system that looks something like this: grid[x][y] = set (for the start with set/unset, later maybe with colors)
On love.mousepressed get x and y and set the surrounding positions in the coordination system.
When the image is finished find some way to send it to a server with a sender a recipient name. As soon as the recipient connects to the server the data gets pushed or downloaded.

Well, that is the plan but I kinda already have problems with the coordinate system.
I tried several ways to create one in the love.load with every position set to "unset".
If this is a bad idea please tell me how to do it better.

What I tried so far:

Code: Select all

grid = { }
for xInit = 0, 799, 1 do
	for yInit = 0, 599, 1 do
		grid.xInit = {}
		grid.xInit.yInit = "unset"
	end
end

Code: Select all

	grid = { }
	xtemp = 0
	ytemp = 0
	for xInit = 0, 799, 1 do
		ytemp = 0
		for yInit = 0, 599, 1 do
			
			line = {[xtemp] = {[ytemp] = "unset"}}
			table.insert(line, grid)
			ytemp = ytemp + 1
		end
		xtemp = xtemp + 1
	end
Also some other variations but they were all kinda unsuccessful.

If there is another thread for trivial syntax questions like this one, please redirect me there.

Re: Beginner Questions: Drawing with Lua and syntax

Posted: Mon Aug 06, 2012 9:30 pm
by bartbes
kaizari wrote:

Code: Select all

grid = { }
for xInit = 0, 799, 1 do
	for yInit = 0, 599, 1 do
		grid.xInit = {}
		grid.xInit.yInit = "unset"
	end
end
This one almost works, try this:

Code: Select all

grid = { }
for xInit = 0, 799, 1 do
	grid[xInit] = {}
	for yInit = 0, 599, 1 do
		grid[xInit][yInit] = "unset"
	end
end

Re: Beginner Questions: Drawing with Lua and syntax

Posted: Mon Aug 06, 2012 10:33 pm
by kaizari
Thank you!
I just realised that i have to add some system to tell the order of the pixels if I'm adding different colors.

Anyway I'm going to code and report back if I encounter some more problems or when I finished the code.