Page 2 of 2
Re: Problem with inserting table into table
Posted: Thu Jul 16, 2009 4:43 pm
by bartbes
nan is the lua standard way of doing that. This might be generated by a divide-by-zero error, check if that occurs.
Re: Problem with inserting table into table
Posted: Thu Jul 16, 2009 5:33 pm
by Matkins
I've got it working now. For some reason on line 110 and 111 i was giving each new body the same x, y coords as the old exploded body. So basically i was spawning them all in one spot. I've now changed it to xRand and yRand, which is what it was always supposed to be, I was just too tired to notice.
My only concern now is that if xRand and yRand values all happen to all equal the same for each new body, that will cause the problem to occur again. I don't fully understand the problem, I'm thinking perhaps all these points in the same place was calling the as of yet empty merge() function to call infinitely. Well, I think I'll be able to figure things out for myself from here on.
Sorry for being dopey... Thanks for helping.
Re: Problem with inserting table into table
Posted: Thu Jul 16, 2009 6:31 pm
by Robin
Matkins wrote:Well, I think I'll be able to figure things out for myself from here on.
But I have a suggestion for you...
Well, I'll post it anyway: you could make a table filled with unique coordinates, then, for each new body, you take a random entry from the table, and remove it. That would guarantee the uniqueness of the coordinates of the new bodies, although it might be too inefficient...
Re: Problem with inserting table into table
Posted: Thu Jul 16, 2009 6:59 pm
by Matkins
Thanks for the suggestion, I may try something like that.
Re: Problem with inserting table into table
Posted: Fri Jul 17, 2009 1:05 pm
by appleide
I'm not sure if this caused the problem... but I sense something's up here.
Code: Select all
function vect(m1x, m1y, m2x, m2y)
local dx = m2x - m1x
local dy = m2y - m1y
local d = math.sqrt(dx^2 + dy^2)
local vx = dx/d
local vy = dy/d
return d, vx, vy
end
if x, y == x1, y1, then dx and dy would be zero... If dx==dy==0, then d=0, then you have a divide by zero problem with vx, vy. The two 'problems' are returned, and used in calculating body
.x and body.y.
Re: Problem with inserting table into table
Posted: Mon Jul 27, 2009 1:33 pm
by Matkins
appleide wrote:I'm not sure if this caused the problem... but I sense something's up here.
Code: Select all
function vect(m1x, m1y, m2x, m2y)
local dx = m2x - m1x
local dy = m2y - m1y
local d = math.sqrt(dx^2 + dy^2)
local vx = dx/d
local vy = dy/d
return d, vx, vy
end
if x, y == x1, y1, then dx and dy would be zero... If dx==dy==0, then d=0, then you have a divide by zero problem with vx, vy. The two 'problems' are returned, and used in calculating body
.x and body.y.
Thanks for this. I think you're right, I'll try fixing it this evening.