Howdy, Stranger!

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

Readimage compile error vs exists(nil)

in Questions Posts: 20

Readimage seems to give a error when a image file is not found. The documentation said it would return nil if it could not load a image. Am I doing something wrong?

This code was in the setup() function. The main code is in this github repo : https://github.com/Pakz001/Codea-examples/tree/main/SpriteEditor

    --savedimage = image(320,240)
    --saveImage(asset.documents.."savedimage.png",savedimage)
    savedimage = readImage(asset.documents.savedimage)
    if savedimage==nil then
        savedimage = image(320,240)
        saveImage(asset.documents.."savedimage.png",savedimage)
        print("created new save..")
    else
        getgridfromimage(1,1,cellshor,cellsvert)
        print("reading image")
    end

Comments

  • dave1707dave1707 Mod
    Posts: 9,988

    @Pakz This is how I read an image if it may or may not exist yet. This returns nil. You need the .. and the “ “.

        a=readImage(asset.documents.Dropbox.."img")
    
  • Posts: 20

    Ok, I changed it and it seems to load correctly.

    Need to test it on a different ipad though, but this makes sense.

    Thx.

Sign In or Register to comment.