Particle/Pressure Detection

  • TheAwesomeMutant
    31st Dec 2016 Member 0 Permalink

    I want to detect when a particle is on screen. Anywhere onscreen. Also, I want to detect for the HIGHEST pressure onscreen, everywhere.

  • LBPHacker
    31st Dec 2016 Developer 0 Permalink

    And I want context. Is this a script? A save with a machine that detects stuff?

     

    OMG sorry. I jumped here from the forum index, didn't see that it was in the scripting section. A proper answer is coming up.

     

    if sim.parts()() then -- note the double function call
        -- stuff done when there are particles on the screen
    end

    -- * I couldn't find a way to query the max positions (152 and 95 below) in a portable way
    -- * sim.XRES and sim.YRES give us the screen size,
    --   but we would need something like sim.CELL to get the pressure map size
    -- * you could have a loop at the beginning
    --   that tries to read pressure from bigger and bigger coords until it errors
    local highest_pressure = -math.huge
    for ix = 0, 152 do
        for iy = 0, 95 do
            highest_pressure = math.max(highest_pressure, sim.pressure(ix, iy))
        end
    end

    Edited 3 times by LBPHacker. Last: 31st Dec 2016