Problem with inserting table into table

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Problem with inserting table into table

Post 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.
Matkins
Citizen
Posts: 53
Joined: Mon Mar 23, 2009 5:12 pm

Re: Problem with inserting table into table

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Problem with inserting table into table

Post 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...
Help us help you: attach a .love.
Matkins
Citizen
Posts: 53
Joined: Mon Mar 23, 2009 5:12 pm

Re: Problem with inserting table into table

Post by Matkins »

Thanks for the suggestion, I may try something like that.
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: Problem with inserting table into table

Post 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.
Matkins
Citizen
Posts: 53
Joined: Mon Mar 23, 2009 5:12 pm

Re: Problem with inserting table into table

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

Who is online

Users browsing this forum: Google [Bot] and 3 guests