Why isn't this working?

  • Videogamer555
    30th Dec 2011 Member 0 Permalink
    This when used with a particle causes anything within a distance of 20 pixels of a pixel of an element with this in its update function to get hot very quickly. Each frame that is processed in the simulation any pixel that is in a circle that has a 20 pixel radius from a particle of this element will have a temperature of 500 added to it. So after 2 frames, any particle within this distance will have gained a total temperature of 1000 (in addition of course to whatever temperature it started with). 3 frames = 1500K, etc.

    At least that what it's SUPPOSED TO DO. But it doesn't work. Can someone here please identify any typos which may be preventing this code from working?

    for scany = 0,20 do
    maxscanx=math.sqrt(400-(scany^2))
    for scanx = 0,maxscanx do
    tpt.set_property("temp",tpt.get_property("temp",x+scanx,y+scany)+500,x+scanx,y+scany)
    tpt.set_property("temp",tpt.get_property("temp",x+scanx,y-scany)+500,x+scanx,y-scany)
    tpt.set_property("temp",tpt.get_property("temp",x-scanx,y+scany)+500,x-scanx,y+scany)
    tpt.set_property("temp",tpt.get_property("temp",x-scanx,y-scany)+500,x-scanx,y-scany)
    end
    end
  • mniip
    30th Dec 2011 Developer 0 Permalink
    lines 1-3:

    for scany = 0,20 do
    maxscanx=math.sqrt(400-(scany^2))
    for scanx = 0,maxscanx do

    replace with:

    for scany = -20,20 do
    maxscanx=math.sqrt(400-(scany^2))
    for scanx = -maxscanx,maxscanx do
  • Videogamer555
    30th Dec 2011 Member 0 Permalink
    Sorry it doesn't work. It doesn't like negative numbers in "for loops".

    The other thing that may be a problem is that instead of calculating the all loop itterations within a single frame of animation, it calculates each itteration on each frame (at least I think this may be what is going on). So it doesn't work as it should.

    This is my current code.
    for scany = -20,20 do
    maxscanx=math.sqrt(400-(scany^2))
    for scanx = -maxscanx,maxscanx do
    tpt.set_property("temp",tpt.get_property("temp",x+scanx,y+scany)+50,x+scanx,y+scany)

    end
    end
  • jacksonmj
    30th Dec 2011 Developer 0 Permalink
    Check whether the particle exists with tpt.get_property("type",...) before trying to access its temperature.

    For particles which don't exist, trying to get any property other than type will cause an error and stop the update function from running.
  • Videogamer555
    30th Dec 2011 Member 0 Permalink

    jacksonmj:

    Check whether the particle exists with tpt.get_property("type",...) before trying to access its temperature.

    For particles which don't exist, trying to get any property other than type will cause an error and stop the update function from running.

    Thanks for the info, that fixed the problem.