New image is `nil`

Why is my image equal to nil here?

    local image = new gfx.image.new(32, 32)
    if image == nil then
        error("Failed to create image") -- Handle errors in case image creation fails
    end
    gfx.pushContext(image)
    gfx.drawRect(8, 8, 16, 16)
    gfx.popContext()

There are no other sprites, I'm not doing anything excessive with memory.

Typo on my part. It's difficult to stop writing new for new objects.

The solution is to delete the new keyword so it becomes:

local image = gfx.image.new(32, 32)
2 Likes