Beginner Questions: Drawing with Lua and syntax

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
kaizari
Prole
Posts: 2
Joined: Mon Aug 06, 2012 8:40 pm

Beginner Questions: Drawing with Lua and syntax

Post 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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Beginner Questions: Drawing with Lua and syntax

Post 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
kaizari
Prole
Posts: 2
Joined: Mon Aug 06, 2012 8:40 pm

Re: Beginner Questions: Drawing with Lua and syntax

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

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 6 guests