Problem with inserting table into table
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Problem with inserting table into table
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
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.
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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Problem with inserting table into table
But I have a suggestion for you...Matkins wrote:Well, I think I'll be able to figure things out for myself from here on.
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...
Help us help you: attach a .love.
Re: Problem with inserting table into table
Thanks for the suggestion, I may try something like that.
Re: Problem with inserting table into table
I'm not sure if this caused the problem... but I sense something's up here.
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.
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
Re: Problem with inserting table into table
appleide wrote:I'm not sure if this caused the problem... but I sense something's up here.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.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
Thanks for this. I think you're right, I'll try fixing it this evening.
Who is online
Users browsing this forum: No registered users and 2 guests