generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Unreachable line in loop (BlobbyBlop Gravity Model)

Previous Thread :: Next Thread 
blanman is not online. blanman
Joined: 15 Mar 2008
Total Posts: 1750
09 Aug 2016 04:57 PM
I'm peeking at a very interesting module, that does a really great job with relative gravity. ( https://www.roblox.com/Planetary-Gravity-item?id=202227526 )

Things work for added characters, but it seems to goof up with loose parts ('added bodies')

I've combed through and isolated a line that doesn't appear to execute. I Have to be missing something, because it shouldn't be possible for this one line not to execute, while the others do.

I have inserted 4 print lines, the 3rd one never executes.

It doesn't seem to be an issue with the construction of the loop that directly contains the lines, because an IDENTICAL loop runs just fine moments before, in the same function.



((Function starting at line 221 in the PlanetaryGravity Script))

function InfluenceMeta:Update()
for part, mass1 in pairs(self.Bodies) do
print ("this line is reached, and executes no problem")
part.PlanetaryForce.force = Vector3.new(0, 9.81*20*mass1, 0);
end
for char, handle in pairs(self.Characters) do
handle.Force.force = Vector3.new(0, 9.81*20*handle.Mass, 0);
handle.Force.DownVector.Value = Vector3.new(0, 0, 0);
end
for well, wellConfig in pairs(self.Wells) do
print(" It Reaches this lne")
for part, mass1 in pairs(self.Bodies) do
print ("This line is unreachable")
part.PlanetaryForce.force = part.PlanetaryForce.force + mass1 * ComputeAcceleration(well, wellConfig, part.Position)
end
for char, handle in pairs(self.Characters) do
print ("But this one is reachable??")
local force = handle.Mass * ComputeAcceleration(well, wellConfig, handle.ForcePart.Position)
if not handle.Grounded then
handle.Force.force = handle.Force.force + force;
end
if force.magnitude > handle.Force.DownVector.Value.magnitude then
handle.Force.DownVector.Value = force;
end
end
end
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
09 Aug 2016 05:00 PM
if you have a loop that doesn't break, then break it


Report Abuse
blanman is not online. blanman
Joined: 15 Mar 2008
Total Posts: 1750
09 Aug 2016 05:04 PM
The loops all close just fine, the module wouldn't be working otherwise, but I just checked to make sure.

The loops are certainly finishing. They're only looping for a few children in a few small tables
Report Abuse
kools is not online. kools
Joined: 11 Jan 2009
Total Posts: 1659
09 Aug 2016 05:05 PM
The thing to conclude is that self.Bodies has become an empty table, so it is never executed. Throw a print statement before the looop executes that prints how many elements self.Bodies has (#self.Bodies). I bet it is zero for some reason.
Report Abuse
blanman is not online. blanman
Joined: 15 Mar 2008
Total Posts: 1750
09 Aug 2016 05:09 PM
For each Gravity well:
Execute a for-loop until it ends (loop for members of bodies table)
Executes another for-loop until it ends (loop for members of character table)


It never executes the print line in the bodies-loop, which is bewildering, because it has to finish that loop before moving on to the character one, which does finish.

It shouldn't be an issue with the first loops construction
(for part, mass1 in pairs(self.Bodies) do)

Because that exact line of code is called earlier in the same function before the nested loops, and it executes perfectly


Report Abuse
blanman is not online. blanman
Joined: 15 Mar 2008
Total Posts: 1750
09 Aug 2016 05:14 PM
I took a decade writing that response above.

I'm not very familiar with tables and roblox -- it entered my mind that the table could just be empty, but it seemed impossible for the table to suddenly be empty. The last thing that happened was that it literally just looped through self.bodies and changed some force values
Report Abuse
kools is not online. kools
Joined: 11 Jan 2009
Total Posts: 1659
09 Aug 2016 05:33 PM
Try it. Try printing the number of elements in self.Bodies. I have no idea why it would become empty, or uniterable, but pairs is not yielding anything.
Report Abuse
blanman is not online. blanman
Joined: 15 Mar 2008
Total Posts: 1750
09 Aug 2016 05:53 PM
Oh, I had and you were correct. It's the only thing that could possibly explain the behavior, short of a huge flaw in my own understanding of the code.

I'm going to dive back through the modules and try to figure out how this could be occurring.

Any advice about visualizing the table - while I'm looking over all the code and figuring out how it manages to happen?
Report Abuse
blanman is not online. blanman
Joined: 15 Mar 2008
Total Posts: 1750
09 Aug 2016 06:27 PM
Oh, it seems as if I've run into the impossible once again.

Before, during, and after the first loop - #self.Bodies prints a 0
(This is a loop that I know works. If I comment out the force assignment, there's an obvious effect on the game)


print (#self.Bodies)

for part, mass1 in pairs(self.Bodies) do
print (#self.Bodies)
part.PlanetaryForce.force = Vector3.new(0, 9.81*20*mass1, 0);


end
print (#self.Bodies)



When I added some details to the prints - it was clear that it was looping properly, repeating 'During loop, #self.Bodies value = 0' exactly as many times as there were parts in the work-space

At this point, my lack of knowladge about lua data structures is really getting in the way.




These parts are assigned to self.bodies through this function:

function InfluenceMeta:AttachPart(part)

if not part:FindFirstChild('PlanetaryForce') then Instance.new("BodyForce", part).Name = 'PlanetaryForce'; end

self.Bodies[part] = part:GetMass();


self.bodies is defined by this function at the end of the script:

'self' is referencing InfluenceMeta in all of these functions

InfluenceMeta being initialized as:



local InfluenceMeta = {};

InfluenceMeta.Characters = nil;
InfluenceMeta.Bodies = nil;
InfluenceMeta.Wells = nil;
InfluenceMeta.Name = "unnamed";




Near the end of the script, The table is manipulated for a toString function.
I doubt the issue is here, but I don't have a grasp on what's being done to it, so I can't really say.


function InfluenceMeta:tostring()
return "Gravity Set: " .. self.Name;
end

InfluenceMeta = {__index = InfluenceMeta, __tostring = InfluenceMeta.tostring};

return function(name)
local t = setmetatable({}, InfluenceMeta);
t.Characters = {};
t.Bodies = {};
t.Wells = {};
t.Name = name;
return t;
end
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image