Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Output when using air code

edited October 2014 in Bugs Posts: 45

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 :-)

Comments

  • Posts: 1,976

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

  • edited November 2014 Posts: 45

    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?

  • edited November 2014 Posts: 502
    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 :-/

  • edited November 2014 Posts: 502

    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
    
Sign In or Register to comment.