Element Not Growing

  • MrDucku
    2nd Jul 2016 Member 0 Permalink

    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!

  • DanielGalrito
    2nd Jul 2016 Member 0 Permalink

    Maybe instead of "sim.partProperty(r, sim.FIELD_TYPE, elem.PARELMOD_PT_FUNGUS)" try  "sim.partChangeType(r, elem.PARELMOD_PT_FUNGUS)" ?

  • MrDucku
    2nd Jul 2016 Member 0 Permalink

    I already tried that earlier, I re tried just know as well, didn't work either time

  • DanielGalrito
    2nd Jul 2016 Member 0 Permalink

    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)

  • MrDucku
    2nd Jul 2016 Member 0 Permalink

    I really don't know what's going on because that didn't work either...

  • jombo23
    3rd Jul 2016 Member 0 Permalink

    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

  • MrDucku
    3rd Jul 2016 Member 0 Permalink

    I've also compltely gotten rid of the if statement with the random numbers, aand it still doesn't work, no errors, no growth

  • LBPHacker
    3rd Jul 2016 Developer 1 Permalink

    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.

    Edited once by LBPHacker. Last: 3rd Jul 2016
  • MrDucku
    3rd Jul 2016 Member 0 Permalink

    Awesome, took some ideas from all around and mooshed them together, fixed! thank you!