Help Support the Baja Engine! Donate to Breezeway Studios!
Debugging

Search:

Track/Watch


If you want to watch the value of a particular variable in real time, use the track command. Simply call 'track(luaexpression [String])' from the console or a script. The tracked variable will be shown when the console is visible (press tab).

For Example:

Code

track("obj.mycube.pos")


Defensive Programming


Lua is a dynamically typed language, meaning that the language itself doesn't check the type of objects, ie. whether the argument to a function is a string or a number. This allows considerably flexibility, however it can cause bugs to occur if your functions expect data is one format but they're accidentally sent in another.

To combat this, you should validate the input to important functions. This includes checking the type of the input, and checking if the value is 'sane'.

For example:

Code

function myfunction(name, value)
        if type(name) ~= "string" then
                print(debug.traceback())
                print("error, myfunction, name should be a string.")
                return
        end

        if type(name) ~= "number" then
                print(debug.traceback())
                print("error, myfunction, value should be a number.")
                return
        end

        if value > 10 or value < 0 then
                print(debug.traceback())
                print("error, myfunction, value is too large or too small.")
                return
        end

        --now proceed normally

end