touched() running before setup()?

So I don’t know if this is even a minor problem, or if it’s just limited to the editor, or whatever but anyway I felt like sharing it.

so you run the below test code, tapping the screen should print (155, 0, 0, 255). BUT, if you refresh it using the refresh icon and tap immediately after, it only prints nil

-- Test code, touched() is running before setup()?
-- You need to tap the screen quickly after refreshing to see this
-- red should print (155, 0, 0, 255)
-- but if you refresh and tap fast enough you just get nil
function setup()
    red = color(155,0,0)
    blue = color(153, 153, 223, 255)
    green = color(0,155,0)
    yellow = color(200,200,0)
end

function draw()
    background(40, 40, 50)
    strokeWidth(5)
end

function touched(touch)
    if touch.state == BEGAN then
        print(red)
    end
end

That’s because it takes some time for the program to start before it runs the setup function. The touched function runs as soon as you tap the screen so the variable red hasn’t been initialized yet and prints nil. Put a print statement at the start of setup and you’ll see that setup hasn’t run yet when you tap the screen after refresh.