Hello!
How would I go about creating a loop to delete multiple script fires at once? I want to make a while loop so that I can delete several objects without having to copy-paste the RemoveScriptFire command. Below is an example of the script I’m working on:
f1 = StartScriptFire(x1, y1, z, spread, gas)
f2 = StartScriptFire(x2, y2, z, spread, gas)
f3 = StartScriptFire(x3, y3, z, spread, gas)
f4 = StartScriptFire(x4, y4, z, spread, gas)
f5 = StartScriptFire(x5, y5, z, spread, gas)
RemoveScriptFire(f1)
RemoveScriptFire(f2)
RemoveScriptFire(f3)
RemoveScriptFire(f4)
RemoveScriptFire(f5)
I’ve tried a few things but so far nothing has worked.
Any help is appreciated.
Instead of f1, f2, f3… do fires[1], fires[2], etc.
Then when cleaning up, do foreach fire in fires …
tl;dr: use a table and loop through the table.
fires = { --Put Fires Here
{fire = "f1", x = "", y = "", z = ""},
}
for theId,theItems in pairs(fires) do
theItems.fire = StartScriptFire(theItems.x, theItems.y, theItems.z, spread, gas)
end
for theId,theItems in pairs(fires) do
RemoveScriptFire(theItems.fire)
end
if my brain is still functioning correctly this should be how you want it
or
local fires = {
{x = 123, y = 123, z = 123},
{x = 123, y = 123, z = 123},
{x = 123, y = 123, z = 123},
{x = 123, y = 123, z = 123},
{x = 123, y = 123, z = 123},
}
for k,v in ipairs(fires) do
v.handle = StartScriptFire(v.x, v.y, v.z, spread, gas)
end
for k,v in ipairs(fires) do
RemoveScriptFire(v.handle)
end
Ipairs is quicker, misread post before.
ipairs is not faster, it just stops when a table contains a nil value.
Thanks for your replies, got it working well now!
No. ipairs is used on sequential numeric tables. It won’t “stop” if it contains a nil value. It will stop if it’s not sequential. You should be using pairs and ipairs appropriately, and in this case, you would use ipairs since it is a sequential numeric table.
Yes, ipairs does everything you said, until it meets a nil value, then it stops.