Can somebody write a script that takes particles of a certain type (SAND, PLNT, etc.) and converts them to a random particle-- from a weighted list: certain chances for certain particles.
In Lua, of course.
Here's how I would code it in Python, if it helps (what I don't understand is in braces):
def randreplace(part,weightdict):
for z in {particles}:
if {z.type}==part:
{z.type}==weightedrandom(dict) #A weighted random choice algorithm
That's it, I think.
{particles}: Going through all the particles. For simplicity, I assume it's a list.
{z.type}: I assume particles are classes, and type is the element- sand, plnt... Thus, changing z.type would change the particle.
Could someone do this (and tell me how I would run it), and explain to me the things in braces?
(Also, I love how I make titles sound like scholarly articles)
function magic (part, choices)
if type(part) == "number" then part = tpt.element(part) end
tpt.start_getPartIndex()
while tpt.next_getPartIndex() do
i = tpt.getPartIndex()
if sim.partProperty(i, "type") == part then
-- TODO improve randomness
sim.partChangeType(i, choices[math.random(#choices)])
end
end
end
-- a script that takes particles of a certain type (SAND, PLNT, etc.) and
-- converts them to a random particle
-- lolboxes
magic.txtnext to the Powder Toy program, then just enter
dofile("magic.txt")into the console. After that you can invoke the script by writing
magic("dust", {"vibr", "elec", "phot"}). Then dust will be replaced by either VIBR, ELEC or PHOT.
Instead of using a table for 'choices', couldn't you do this?
function magic (part, ...)
choices = []
for i,v in ipairs(arg) do
choices[i] = tostring(v)
end
--etc
end
That way, instead of doing magic(dust, {"stuff", "more stuff", etc}), they could just do magic(dust, stuff, more stuff, etc).
EDIT: What on earth is happening to my code boxes? Just ignore them for now.
@mniip: Why?