I'm currently making a new element my friend requested I add to my new mod, however it keeps saying there's an error, I've disabled all mods but Texter, Layering Helper and TPTMP, the element script looks to be normal and it works fine, I have no idea why it still gives me an error message.
local psac = elements.allocate("TPT", "PSAC")
elements.element(psac, elements.element(elements.DEFAULT_PT_SOAP))
elements.property(psac, "Name" , "PSAC")
elements.property(psac, "Description" , "Positronic acid, reacts violently with matter, weak acid.")
elements.property(psac, "Color", 0xFF20BB)
elements.property(elem.TPT_PT_PSAC, "Update", --*1
function(i,x,y,s,nt) --1
if s ~=8 and nt ~=0 and nt - s > 0 then --2
if math.random(1,100) == 10 then --3
for r in sim.neighbors(x,y,1,1) do --4
if sim.partProperty(r, "type") ~= elements.DEFAULT_PT_DMND then --5
if sim.partProperty(r, "type") ~= elements.DEFAULT_PT_VACU then --6
if sim.partProperty(r, "type") ~= elements.DEFAULT_PT_VOID then --7
if math.random(1,6) == 3 then --8
sim.partKill(r)
sim.partProperty(i, "temp", sim.partProperty(i, "temp")+1600) --It says there's an error at this line, i've used this peice of code with a different temp on a different element above and it doesn't give me an error there.
if math.random(1,25) == 20 then --9
sim.partKill(i)
end --9
end --8
end --7
end --6
end --5
end --4
end --3
end --2
end --1
) --*1
for r in sim.neighbors(x,y,1,1) do --4 causing the problem because inside it parts can kill self in this line
sim.partKill(i)
But after part got killed cycle is continues and as result next iteration trying to access already deleted element id
To fix this you can add "return" after line "sim.partKill(i)"
or place lines:
if math.random(1,25) == 20 then --9
sim.partKill(i)
end --9
after for cycle.