WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   General Authoring Discussion (https://www.wowinterface.com/forums/forumdisplay.php?f=20)
-   -   Naive Question: assert() error message (https://www.wowinterface.com/forums/showthread.php?t=55845)

mtp1032 11-12-17 08:03 PM

Naive Question: assert() error message
 
This is my first foray into LUA and WoW Addon development. So apologies in advance for the naivity.

Note the call to assert() in the function below. While it terminates the program correctly, it doesn't print the error message to the chat frame.

This is so simple that I'm convinced I'm missing something. Does assert(), for example, use a different output that the chat frame?

Any help would be very much appreciated.

Code:

function debugPlay()

        assert( nil, "function terminated.")
       
        stackInfo = debugstack()
        print( stackInfo )
       

        --
        -- Get the line number from where the function was called
        --
        for number in string.gmatch(stackInfo, "%d+>")
                do
                        print("Function definition at line ", string.match( number, "%d+"))
                end
       
       
        --
        -- Get line number where function was called.
        --
        for number in string.gmatch(stackInfo, "%d+:")
                do
                        print("Function called at line ", string.match( number, "%d+"))
        end

end


Kanegasi 11-12-17 10:06 PM

assert() does not print a chat message, it raises a Lua error. You won't see it if you have Lua errors disabled or whatever error catching addon you may be using is hiding it.

Fizzlemizz 11-12-17 10:13 PM

It prints to the error output.

If you have BugGrabber and BugSack intalled

Code:

/run local function debugPlay()
        assert( nil, "function terminated.")
end
 debugPlay()


BugSack will display:
Quote:

1x [string "local function debugPlay() assert( nil, ..."]:1: function terminated.
Edit: Oops too late :)

mtp1032 11-13-17 07:15 AM

Kanegasi and Fizzlemizz - Thanks to you both. I thought it might be something like that.

MunkDev 11-13-17 01:47 PM

Completely off-topic, but since you mentioned you're new at this, please have a look at how to scope your variables properly.
Generally speaking, global variables should only be used for things you want to access externally.


All times are GMT -6. The time now is 11:35 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI