How do I complain in Codea?

Is there an error-reporting function? So that if I write a function and want to check that the input is acceptable before processing it then I can have the function complain vociferously if the input is wrong.

Are you thinking of is an assert(condition, message), type of function? You could implement it, but at the moment you can only print to the output window.

I’ve been looking at adding a more obvious runtime error system that draws in red letters to the screen. But you could create a custom one for now.

Note this uses Bortels’ font code: https://github.com/bortels/HersheyCodea

-- This uses Bortels' Hershey Roman Simplex font code
function setup()
    f = HersheyRomanSimplex()

    frame = 1 -- for testing
end

function assert( condition, message )
    if condition == false then
        pushStyle()
        pushMatrix()
        clearMatrix()
        
        noSmooth()
        stroke(255,0,0)
        strokeWidth( 2 )

        f:drawstring( "Assertion failed: " .. message, 20, HEIGHT - 35 )

        popMatrix()
        popStyle()
    end
end

-- Simple test case
function draw()
    background(0)

    frame = frame + 1

    assert( frame < 30, "frame count is too high" )
end

So this lets you complain in big letters on the screen when a test condition is false.

or you could just print(). :slight_smile: