Page 2 of 2

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

Posted: Tue Mar 29, 2011 8:00 am
by Robin
Could you give us a .love? It works a lot better if we can see for ourselves what is going wrong.

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

Posted: Mon Apr 11, 2011 9:16 pm
by LuaWeaver
Robin wrote:Could you give us a .love? It works a lot better if we can see for ourselves what is going wrong.
Of course. It took me a little while to respond, had a lot of other stuff goin on.

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

Posted: Tue Apr 12, 2011 5:32 am
by Robin
First, this doesn't answer your question, but helper.lua is completely useless. math.expon(x, y) is the same as x^y, and love.getSize() always returns the width. Better just use getWidth() and getHeight() in your main.lua (also, it doesn't matter, because you make the window square anyway.

This line:

Code: Select all

changeBoard(key+0, 1)
crashes if you press a non-numeric key.
Better use something like:

Code: Select all

if tonumber(key) then
    changeBoard(tonumber(key), 1)
end
Also, I don't think you need to use drawq here.

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

Posted: Sun Apr 17, 2011 6:20 pm
by LuaWeaver
Well, thanks. I did the math.expon and love.GetSize() as a test for require(''). Simple as that. I know these are useless, I just wanted to test it out. :P. This still can't answer my problem... time to rewrite the entire thing...

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

Posted: Mon Apr 18, 2011 12:45 am
by Jesus
if piece~=0 then
check the documentation on your language

be sure that the ~= operation that the

~

is the operator you're trying to use

it could be inversion

or it could be a logical not

most of the time a logical not is

!

making the operator

!=

check to make sure that you're not doing math when you are trying to evaluate a (logical) equation

for example if you're doing math then

piece invert equals 0

this means piece = piece invert 0

this evaluates to piece = 0

this does not make sense when evaluating a logical equation because it does not make sense to ask

if piece = piece invert 0

what this (what does not make sense) would do is

if 0

if 0 is always false

math during an if then statement can be done

but instead just try

if piece != 0 then


if the language you're using uses a different logical operator for a logical not then find the operator and replace the above statement with that operator.

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

Posted: Mon Apr 18, 2011 2:17 am
by Taehl
Lua uses ~= for not-equal. It does not use != like others do.

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

Posted: Mon Apr 18, 2011 2:25 am
by bmelts
LuaWeaver, here's your problem, way up top in love.load():

Code: Select all

local q={0, 0, 0, 0, 0, 0, 0, 0}
board={q, q, q, q, q, q, q, q}
The reason this fails is tricky, and has to do with the way tables work in Lua. In a nutshell, q is just a reference to a single table, not a table itself. So when you construct board like that, you're just telling it to use the same reference 8 times. That means you've got 8 references to 1 table, not 8 different tables. As such, any change to one of board's members affects all of them, since they're all the same table. This can be fixed by doing something akin to the following:

Code: Select all

for i=1,8 do
  board[i] = {0, 0, 0, 0, 0, 0, 0, 0}
end
This will create 8 distinct tables, and fix the issue you're having.

As for the reason it changes the entire row, and not the column... well, I'm afraid you've also got your rows and columns backwards. ;)

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

Posted: Mon Apr 18, 2011 6:11 am
by Jasoco
You can also do this, which I recommend getting used to typing because it is much easier to make bigger grids...

Code: Select all

grid = {}
for x = 1, width do
  grid[x] = {}
  for y = 1, height do
    grid[x][y] = whatever
  end
end
If you need to start the grid at base zero, just do 0 to width/height MINUS ONE (-1). And you can replace "whatever" with whatever. Numbers, strings, or even another table for holding the different statistics of the grid tile. Where width and height are the size of the grid to create.

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

Posted: Mon Apr 18, 2011 9:27 pm
by LuaWeaver
anjo wrote:LuaWeaver, here's your problem, way up top in love.load():

Code: Select all

local q={0, 0, 0, 0, 0, 0, 0, 0}
board={q, q, q, q, q, q, q, q}
The reason this fails is tricky, and has to do with the way tables work in Lua. In a nutshell, q is just a reference to a single table, not a table itself. So when you construct board like that, you're just telling it to use the same reference 8 times. That means you've got 8 references to 1 table, not 8 different tables. As such, any change to one of board's members affects all of them, since they're all the same table. This can be fixed by doing something akin to the following:

Code: Select all

for i=1,8 do
  board[i] = {0, 0, 0, 0, 0, 0, 0, 0}
end
This will create 8 distinct tables, and fix the issue you're having.

As for the reason it changes the entire row, and not the column... well, I'm afraid you've also got your rows and columns backwards. ;)
Ah. I didn't know that. You got me there! Also, for columns... oops... thanks for the help. I can make my own helper.lua thingy so I can create a function to do that, cause my games are gonna be like that. Thanks! I am so glad I still have the .love on here, cuz now I can just edit it :crazy:

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

Posted: Tue Apr 19, 2011 11:27 am
by LuaWeaver
LuaWeaver wrote:
anjo wrote:LuaWeaver, here's your problem, way up top in love.load():

Code: Select all

local q={0, 0, 0, 0, 0, 0, 0, 0}
board={q, q, q, q, q, q, q, q}
The reason this fails is tricky, and has to do with the way tables work in Lua. In a nutshell, q is just a reference to a single table, not a table itself. So when you construct board like that, you're just telling it to use the same reference 8 times. That means you've got 8 references to 1 table, not 8 different tables. As such, any change to one of board's members affects all of them, since they're all the same table. This can be fixed by doing something akin to the following:

Code: Select all

for i=1,8 do
  board[i] = {0, 0, 0, 0, 0, 0, 0, 0}
end
This will create 8 distinct tables, and fix the issue you're having.

As for the reason it changes the entire row, and not the column... well, I'm afraid you've also got your rows and columns backwards. ;)
Ah. I didn't know that. You got me there! Also, for columns... oops... thanks for the help. I can make my own helper.lua thingy so I can create a function to do that, cause my games are gonna be like that. Thanks! I am so glad I still have the .love on here, cuz now I can just edit it :crazy:
Huh. Nope. Didn't work. it did make my code have a for loop in my love.load, though. Why I care about that, I don't know. It's not that problem.