so I have my code here (I already have defined the element and all that)
local function fungrow(i, x, y, n, nt)
for r in sim.neighbors(x, y, 1, 1) do
if sim.partProperty(r, sim.FIELD_TYPE) == elem.DEFAULT_PT_NONE then
if math.random(1, 2000) == 739 then
sim.partProperty(r, sim.FIELD_TYPE, elem.PARELMOD_PT_FUNGUS)
end
end
end
end
elem.property(fungus, "Update", fungrow)
and it isn't working, if someone could plese tell me why that'd be great! thanks!
Maybe instead of "sim.partProperty(r, sim.FIELD_TYPE, elem.PARELMOD_PT_FUNGUS)" try "sim.partChangeType(r, elem.PARELMOD_PT_FUNGUS)" ?
I don't know how to use these functions with the prefix sim. , so I used the ones with tpt.
Try:
local function fungrow(i, x, y, n, nt)
if tpt.get_property("type", x+math.random(-1,1), y+math.random(-1,1)) == elem.DEFAULT_PT_NONE then
if math.random(1, 2000) == 739 then
tpt.create(x+math.random(-1,1),y+math.random(-1,1), elem.PARELMOD_PT_FUNGUS)
end
end
end
elem.property(fungus, "Update", fungrow)
I dont know what the randomization is like, but you do understand that it could take well over 2000 updates to (2000 frames) to meet your expectations, so somewhere between 30 seconds and a minute BEST case scenario.
Theres a good chance that the random number WONT ever be 739
sim.neighbours returns an iterator to the particles that are neighbour to the particle passed to sim.neighbours. Their type won't ever be NONE. You'll have to write your own neighbour loop. It's not actually a neighbour loop you're looking for, it's rather an area loop.
Also, DanielGalrito's solution worked for me.