Output when using air code

hi

i’m trying the http.request example.

when i use air code, nothing is shown on the output area, if i don’t use air code, the result shows fine on the output area.

is this a bug? or is it intended? or am i doing someting wrong?

thanks :slight_smile:

Probably due to the fact that setup is only run once, and if you change something in setup it won’t restart automatically.

hi skythecode

i’m very noob to programming / codea therefore…

if i try this code

-- Downloading an image

function setup()

    logoImage = nil

       -- Request some data

    http.request( 'http://codea.io/images/Codea-Image-01.png',didGetImage )

end



-- Our callback function

function didGetImage( theImage, status, head )

    logoImage = theImage

end



function draw()

    background(20,20,40)

    if logoImage ~= nil then

        sprite(logoImage, WIDTH/2,HEIGHT/2,WIDTH)

    end

end

it won’t work with aircode, but ok on the ipad - so this can’t be done via aircode?

sorry for this very noob question, but i don’t get it?

local logoImage = nil

local function didGetImage(theImage, status, head)
    logoImage = theImage
    print("Image loaded.")
    print(status: "..status)
end

function setup()
    http.request( 'http://codea.io/images/Codea-Image-01.png', didGetImage)
end

function draw()
    background(20)
    
    if logoImage then
        sprite(logoImage, WIDTH/2,HEIGHT/2,WIDTH)
    end
end

Will work just fine. Try to restart your app from within AirCode by pressing Ctrl+R.

strange - it won’t work here :-/

I tried myself. @Simeon Must be an AirCode bug?.

function draw()
    background(20)
    if logoImage then
        sprite(logoImage, WIDTH/2, HEIGHT/2, WIDTH)
    else
        http.request("http://codea.io/images/Codea-Image-01.png", function(img, status, head) logoImage = img end)
    end
end