Something odd with Lua

  • Videogamer555
    13th Jan 2012 Member 0 Permalink
    I want to make a filled- circle of plasma so I use the below code
    for yoff=-75,75 do
    for xoff=-math.sqrt((75^2)-(yoff^2)),math.sqrt((75^2)-(yoff^2)) do
    if tpt.get_property("type",x+xoff,y+yoff)==0 then
    tpt.create(x+xoff,y+yoff,"plsm")
    tpt.set_property("life",20,x+xoff,y+yoff)
    end
    end
    end


    I have it check with get_property("type",x+xoff,y+yoff) because I don't want it to crash trying to place a particle where it can't (a pixel that already has an element placed there). Problem is it crashes when it tries to perform get_property on a pixel that isn't in the playing field. As a result, when the particle in question that will generate the plasma sphere is too near the edge of the playing field, part of the circle is offscreen, and it crashes the script. This means that it draws only a few pixels before the for-loops specify a pixel that is offsecreen, which causes the script to cease running so it doesn't ever draw the remaining pixels, even the remaining pixels that ARE at coordinates that fit onscreen never get drawn.

    How do I check in Lua to see if a pair of x-y coordinates specifies a valid pixel (NOT outside of the drawing area)?
  • mniip
    13th Jan 2012 Developer 0 Permalink
    @Videogamer555 (View Post)

    if x>3 and y>3 and x<608 and y<380