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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
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 »

Could you give us a .love? It works a lot better if we can see for ourselves what is going wrong.
Help us help you: attach a .love.
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 »

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.
Attachments
Connect 4.love
(30.42 KiB) Downloaded 189 times
"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 »

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.
Help us help you: attach a .love.
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 »

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...
"your actions cause me to infer your ego is the size of three houses" -finley
Jesus
Prole
Posts: 6
Joined: Mon Apr 18, 2011 12:20 am

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

Post 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.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

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

Post by Taehl »

Lua uses ~= for not-equal. It does not use != like others do.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
bmelts
Party member
Posts: 380
Joined: Fri Jan 30, 2009 3:16 am
Location: Wiscönsin
Contact:

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

Post 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. ;)
User avatar
Jasoco
Inner party member
Posts: 3727
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

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

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

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:
"your actions cause me to infer your ego is the size of three houses" -finley
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 »

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.
"your actions cause me to infer your ego is the size of three houses" -finley
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 8 guests