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
|
  |
| 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
|
  |
| 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 |
|
|
| |
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
| |
|
|
| 16 Nov 2014 03:12 PM |
| That's because his code only works on parts in Workspace. |
|
|
| Report Abuse |
|
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
| |
|
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 |
|
|
|
| 16 Nov 2014 03:15 PM |
| I already suggested GetPartsInRegion3. |
|
|
| Report Abuse |
|
|
DevUndead
|
  |
| Joined: 24 Jul 2014 |
| Total Posts: 558 |
|
| |
|
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
|
  |
| 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
|
  |
| 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 |
|
|