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 » Scripting Helpers
Home Search
 

Re: Test for other objects in a area

Previous Thread :: Next Thread 
DevUndead is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
16 Nov 2014 02:51 PM
print(script.Parent,", ", script.Name)

-------------------------------------------------------------
--------------------------DEVUNDEAD--------------------------
-------------------------------------------------------------

function fireSpread()
for _,v in pairs(workspace:GetChildren()) do
if v.Name == "Wood" then
--test wether another object name wood in nearby
end
end
end


while true do
wait(1)
fireSpread()
end
Report Abuse
DevUndead is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
16 Nov 2014 02:58 PM
How can I make this test for other objects around it with a magnitude function?
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
16 Nov 2014 03:04 PM
local distanceThreshold = 20

function DoCheck(startObj, obj)
     if startObj == obj then return end
     if not obj:IsA("Part") then return end
     if obj.Name ~= "Wood" then return end
     if (startObj.Position - obj.Position).magnitude > distanceThreshold then return end

     -- Spread Code

end

function CheckForNearbyObjects(startObj)
     for _, obj in pairs(game.Workspace:GetChildren()) do
          DoCheck(startObj, obj)
     end
end
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
16 Nov 2014 03:08 PM
Use GetPartsInRegion3.
Report Abuse
DevUndead is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
16 Nov 2014 03:11 PM
snot working m8
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
16 Nov 2014 03:12 PM
That's because his code only works on parts in Workspace.
Report Abuse
DevUndead is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
16 Nov 2014 03:12 PM
than halp
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
16 Nov 2014 03:14 PM
How do you expect to be a developer when you can't solve a problem like this?

I provide outlines of code for people to use to solve their problems; it's not a solution that comes right out of a box. You should have everything you need to know to do what you want to do.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
16 Nov 2014 03:15 PM
I already suggested GetPartsInRegion3.
Report Abuse
DevUndead is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
16 Nov 2014 03:17 PM
xsit Im learning m8
Report Abuse
DevUndead is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
16 Nov 2014 03:21 PM
local distanceThreshold = 20

function DoCheck(startObj, obj)
if startObj == obj then return end
if not obj:IsA("Part") then return end
if obj.Name ~= "Wood" then return end
if (startObj.Position - obj.Position).magnitude > distanceThreshold then return end

Instance.new("Fire", obj)
end

function CheckForNearbyObjects(startObj)
for _, obj in pairs(game.Workspace:GetChildren()) do
DoCheck(startObj, obj)
end
end

CheckForNearbyObjects("Wood")

while true do
DoCheck("Wood", "Wood")
end


Report Abuse
DevUndead is not online. DevUndead
Joined: 24 Jul 2014
Total Posts: 558
16 Nov 2014 03:23 PM
local distanceThreshold = 20

function DoCheck(startObj, obj)
if startObj == obj then return end
if not obj:IsA("Part") then return end
if obj.Name ~= "Wood" then return end
if (startObj.Position - obj.Position).magnitude > distanceThreshold then return end

Instance.new("Fire", obj)
end

function CheckForNearbyObjects(startObj)
for _, obj in pairs(game.Workspace:GetChildren()) do
DoCheck(startObj, obj)
end
end

CheckForNearbyObjects("Wood")

while true do
DoCheck(game.Workspace.Wood, "Wood")
end


15:23:16.794 - Script 'Workspace._Vanilla.Handlers.Fire Handler', Line 27 - global DoCheck
15:23:16.795 - Script 'Workspace._Vanilla.Handlers.Fire Handler', Line 34 - global CheckForNearbyObjects
15:23:16.796 - Script 'Workspace._Vanilla.Handlers.Fire Handler', Line 38
15:23:16.797 - Stack End
Report Abuse
Xsitsu is not online. Xsitsu
Joined: 28 Jul 2009
Total Posts: 2921
16 Nov 2014 03:54 PM
Replace this part:

CheckForNearbyObjects("Wood")

while true do
DoCheck(game.Workspace.Wood, "Wood")
end


With this:

while true do wait(1)
for _, v in pairs(game.Workspace:GetChildren()) do
if v.Name == "Wood" then
CheckForNearbyObjects(v)
end
end
end


The CheckForNearbyObjects() function checks one object against every other object in the Workspace. This object must be an object, so passing the value of "Wood" (which is a string) will not work.

You also will need to iterate throughout all the objects in the game within the main while loop. Beforehand it would have just continuously checked only one object.

It's also probably a good idea to wait a little while inbetween every check cycle. Checking every object against every other object 30 times a second will be very costly on script performance. I recommend doing it at an interval of 1 second for every cycle. Unless you absolutely have to have fire spread instantaneously, 1 second should be a perfect time to wait. It won't be very noticeable to players, and it will mean that the script will perform only 1/30 of the checks it normally would.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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