sim.partProperty() is not working.

  • powder_is_epic
    8th May Member 0 Permalink

    This code doesnt work: (also the name of my element is GMPR if you cant tell.)

     

    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

    sim.partProperty(i, "FIELD_TMP2", 1)
     
    The idea of this code is that whenever it is sparked, its tmp2 is increased by one.
    I get the error: Unknown field (FIELD_TMP2)
    I have no idea why this happens because the wiki page on sim.partProperty() clearly states that FIELD_TMP2 is a valid constant for sim.partProperty() Also i am a bit confused, does sim.partProperty() set a variable for a pixel, or increase it by one, and if it sets a variable, then how would I increase tmp2 each time it is sparked?
  • Jerehmia
    8th May Member 1 Permalink

    You're using a constant, so the right syntax is

     

    sim.PartProperty(i, sim.FIELD_TMP2, 1)

     

    To increment you have to read the value, add 1 to it and write it back:

     

    sim.PartProperty(i, sim.FIELD_TMP2, sim.PartProperty(i, sim.FIELD_TMP2) + 1)

  • powder_is_epic
    8th May Member 0 Permalink

    Thx!

  • 0xHenryMC
    4th July Member 0 Permalink

    Jerehmia:

    You're using a constant, so the right syntax is

     

    sim.PartProperty(i, sim.FIELD_TMP2, 1)

     

    To increment you have to read the value, add 1 to it and write it back:

     

    sim.PartProperty(i, sim.FIELD_TMP2, sim.PartProperty(i, sim.FIELD_TMP2) + 1)

     

     He's right. I have no idea why would you put a string there. That's not how coding works!