Anyone gonna help a newbie? Again... yet Again...

General discussion about LÖVE, Lua, game development, puns, and unicorns.
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Anyone gonna help a newbie? Again... yet Again...

Post by LuaWeaver »

Does anyone see an error in this code? LOVE doesn't say an error to me, but what it does is it doesn't work properly. This is my third topic on coding help :oops: what this is supposed to do is build a grid using my images, fitting the size of the window perfectly. Without the color pieces added, it works fine. But, adding the changing one thing in the board table chanegs the entire row! It's laid out like this: A table containing other tables. When you press a button it checks to see if the the grid space is existent and empty. If so, it changes that value. In this code, it constantly draws that table, so if the table is changed, boom, it changes on the screen. I have the table change working, as said above. But, it changes the row, instead of one piece. If there is an error in this, then there's my problem. If not, I know where the problem is.

Code: Select all

function love.draw()
	if not selected then
		love.graphics.print("PLEASE SELECT A GRID SIZE 4-8", 200, 200)
	else
		for i=1, 8 do
			row=board[i]
			for l=1, 8 do
				local piece=row[l]
				if piece~=0 then
					love.graphics.drawq(piece, grid, w*(i-1), he*(l-1), 0, 1, 1, 0, 0)
				end
			end
		end
	end
end
"your actions cause me to infer your ego is the size of three houses" -finley
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Anyone gonna help a newbie? Again... yet Again...

Post by bartbes »

You should really, really, really use descriptive topic names.

As for the problem itself, it looks like the offending code is the editing code, which you haven't posted.
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: Anyone gonna help a newbie? Again... yet Again...

Post by LuaWeaver »

Code: Select all

function love.keypressed(key)
	if not selected then
		for i=4, 8 do
			if key==""..i then
				selected=i
				setGrid(i)
				w=w/selected
				he=he/selected
				grid=love.graphics.newQuad(0, 0, w, he, w, he)
			end
		end
	else
		for i=1, 8 do
			if ""..i==key then
				changeBoard(i, 1)
			end
		end
	end
end

function setGrid(size)
	for i=1, size do
		local h=board[i]
		for i=1, size do
			h[i]=empty
		end
	end
end

function changeBoard(key, row)
	if board[row][key]~=0 then
		if board[row][key]==empty then
			if turn==red then
				board[row][key]=red
				turn=blue
			else
				board[row][key]=blue
				turn=red
			end
		end
	end
end
"your actions cause me to infer your ego is the size of three houses" -finley
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Anyone gonna help a newbie? Again... yet Again...

Post by bartbes »

LuaWeaver wrote:

Code: Select all

function love.keypressed(key)
		for i=1, 8 do
			if ""..i==key then
				changeBoard(i, 1)
			end
		end
Doesn't that code set the entire row?
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: Anyone gonna help a newbie? Again... yet Again...

Post by LuaWeaver »

How so? It goes to board[row][key] and changes it. How does it set the whole row?
"your actions cause me to infer your ego is the size of three houses" -finley
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Anyone gonna help a newbie? Again... yet Again...

Post by Robin »

LuaWeaver wrote:How so? It goes to board[row][key] and changes it. How does it set the whole row?
Because it is in a for-loop.
Help us help you: attach a .love.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Anyone gonna help a newbie? Again... yet Again...

Post by leiradel »

Robin wrote:
LuaWeaver wrote:How so? It goes to board[row][key] and changes it. How does it set the whole row?
Because it is in a for-loop.
But he only sets the element if ""..i==key...

A better way to write this is changeBoard(key + 0, 1). key + 0 will convert the string key into a number and add zero to it.

As for the problem you're having, I don't know... :?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Anyone gonna help a newbie? Again... yet Again...

Post by Robin »

leiradel wrote:But he only sets the element if ""..i==key...

A better way to write this is changeBoard(key + 0, 1). key + 0 will convert the string key into a number and add zero to it.
I'm wondering about the hacks. What's wrong with tostring() and tonumber()?
Help us help you: attach a .love.
User avatar
leiradel
Party member
Posts: 184
Joined: Thu Mar 11, 2010 3:40 am
Location: Lisbon, Portugal

Re: Anyone gonna help a newbie? Again... yet Again...

Post by leiradel »

Robin wrote:
leiradel wrote:But he only sets the element if ""..i==key...

A better way to write this is changeBoard(key + 0, 1). key + 0 will convert the string key into a number and add zero to it.
I'm wondering about the hacks. What's wrong with tostring() and tonumber()?
Good point, it's just that old habits die hard.
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: Anyone gonna help a newbie? Again... yet Again...

Post by LuaWeaver »

leiradel wrote:
Robin wrote:
leiradel wrote:But he only sets the element if ""..i==key...

A better way to write this is changeBoard(key + 0, 1). key + 0 will convert the string key into a number and add zero to it.
I'm wondering about the hacks. What's wrong with tostring() and tonumber()?
Good point, it's just that old habits die hard.
If I know easy syntax for something, I don't investigate further. I actually prefer the "hacks" because I've used them longer AND I only know about those functions now... :P anyways, I still can't find the error. Please start getting back on topic... :?
"your actions cause me to infer your ego is the size of three houses" -finley
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests