bad argument to #1 partProperty

  • powder_is_epic
    31st July Member 0 Permalink

    I have been on a coding hiatus for awhile, but i came back and was trying to debug my Quantations script, so i could finally get it to work, but i keep getting this error:

    bad argument to #1 partProperty, number expected, got nil


    I am trying to loop through sim.partProperty TMP2 value, then create a spark on a timer, totalling up to ten. I have python experience and im 99% sure i am remembering something from python and using it in lua.

     

    Source Code: [the bolded/italic code is the issue]

     

    function GMPRup(i, x, y, s, nt)

    for r in sim.neighbors(x,y,1,1) do

    if (sim.partProperty(r, "type") == elem.DEFAULT_PT_SPRK) then
    -- Credit to Jerehmia for helping me figure out how sim.partProperty worked.
    sim.PartProperty(i, sim.FIELD_TMP, sim.PartProperty(i, sim.FIELD_TMP) + 1)

    end

    end

    end
    -- Sleep function from some random website on the internet.
    local clock = os.clock

    function sleep(n)

    local t0 = clock()

    while clock() - t0 <= n do end

    end

    i2 = sim.partProperty(i, sim.FIELD_TMP, sim.partProperty(i, sim.FIELD_TMP) + 0)

    for i2=0,10 do

    sleep(2)

    if s ~= nt then
       
    for dx = -1, 1 do
               
    for dy = -1, 1 do
               
    if dx ~= 0 or dy ~= 0 then
               
    sim.partCreate(-1, x + dx, y + dy, elem.DEFAULT_PT_SPRK)

    end

    end

    end

    end

    end
  • Jerehmia
    1st August Member 0 Permalink

    The GMPRup() function ends with the end statement before the sleep() function, so the i vatiable in the bold line doesn't exist.

     

    I'm not sure what you're really trying to do there, because you read a particle property with just i2 = sim.partProperty(i, sim.FIELD_TMP)

    What i2 = sim.partProperty(i, sim.FIELD_TMP, sim.partProperty(i, sim.FIELD_TMP) + 0) does is 1) read the TMP property, 2) add 0 to it, 3) write back the unchanged value to the property, and 4) assign the value to i2.

     

    Also the bold line does nothing constructive because you overwrite the i2 variable in the for loop on the next line without ever using the value you assigned to it in the bold line.

     

    If you really want that i2 for loop inside a particle update function you definitely shouldn't use any kind of sleep function because update functions are intended to run 60 times a second (once every frame).