Anyone gonna help a newbie? Again... yet Again...
- 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...
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.
Re: Anyone gonna help a newbie? Again... yet Again...
Of course. It took me a little while to respond, had a lot of other stuff goin on.Robin wrote:Could you give us a .love? It works a lot better if we can see for ourselves what is going wrong.
- 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
- 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...
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:
crashes if you press a non-numeric key.
Better use something like:
Also, I don't think you need to use drawq here.
This line:
Code: Select all
changeBoard(key+0, 1)
Better use something like:
Code: Select all
if tonumber(key) then
changeBoard(tonumber(key), 1)
end
Help us help you: attach a .love.
Re: Anyone gonna help a newbie? Again... yet Again...
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. . 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
Re: Anyone gonna help a newbie? Again... yet Again...
check the documentation on your languageif piece~=0 then
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.
- 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...
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+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: Anyone gonna help a newbie? Again... yet Again...
LuaWeaver, here's your problem, way up top in love.load():
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:
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.
Code: Select all
local q={0, 0, 0, 0, 0, 0, 0, 0}
board={q, q, q, q, q, q, q, q}
Code: Select all
for i=1,8 do
board[i] = {0, 0, 0, 0, 0, 0, 0, 0}
end
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.
- 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...
You can also do this, which I recommend getting used to typing because it is much easier to make bigger grids...
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.
Code: Select all
grid = {}
for x = 1, width do
grid[x] = {}
for y = 1, height do
grid[x][y] = whatever
end
end
Re: Anyone gonna help a newbie? Again... yet Again...
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 itanjo wrote:LuaWeaver, here's your problem, way up top in love.load():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
local q={0, 0, 0, 0, 0, 0, 0, 0} board={q, q, q, q, q, q, q, q}
This will create 8 distinct tables, and fix the issue you're having.Code: Select all
for i=1,8 do board[i] = {0, 0, 0, 0, 0, 0, 0, 0} end
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.
"your actions cause me to infer your ego is the size of three houses" -finley
Re: Anyone gonna help a newbie? Again... yet Again...
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.LuaWeaver wrote: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 itanjo wrote:LuaWeaver, here's your problem, way up top in love.load():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
local q={0, 0, 0, 0, 0, 0, 0, 0} board={q, q, q, q, q, q, q, q}
This will create 8 distinct tables, and fix the issue you're having.Code: Select all
for i=1,8 do board[i] = {0, 0, 0, 0, 0, 0, 0, 0} end
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.
"your actions cause me to infer your ego is the size of three houses" -finley
Who is online
Users browsing this forum: Ahrefs [Bot] and 8 guests