WoWInterface (
-   General Authoring Discussion (
-   -   Event LUA_WARNING payload 0 and NULL (

AreGee 06-02-20 06:35 PM

Event LUA_WARNING payload 0 and NULL
I did register for the event LUA_WARNING in case it would catch some of the silent errors that I have been getting, and indeed I do receive these events. The problem is that the payload is 0 (null) every single time and I can't for the world understand what is going wrong. I have no problem getting the payload from any of the other events that I am handling.

Here is the function that is receiving and handling the events:


local function AST_Event_LUAWarning(self, event, ...)
 local warnType, warningText = ...
 print("Warning: LUA_WARNING, type: " .. tostring(warnType) .. ", text: " .. warningText)

The function is handled by a generic event handler that I made. It is working for all other events, but I include it in case someone wants to investigate:


local function AST_EventAlreadyRegistered(newEventName)
 assert(type(newEventName) == "string", "Error: function AST_EventAlredyRegistered(newEventName)\n  - Input type is not a 'string'.")

 if not (type(newEventName) == "string") then
  print("Error: function AST_EventAlredyRegistered(newEventName)")
  print("  - Input type is not a 'string'.")
  return false
 for i, item in ipairs(_V.Events) do
  local existingEventName, func = item["eventName"], item["func"]
  if newEventName == existingEventName then
  return true
 return false

local function AST_RegisterEvent(frame, eventName, func)
 if AST_EventAlreadyRegistered(eventName) then
  print("Warning: function AST_RegisterEvent(eventName, func)")
  print("  - Silently dropping double registering of event '" .. eventName .. "'.")
 local item = {frame = frame, eventName = eventName, func = func}
 table.insert(_V.Events, item)

local function AST_MainEventHandler(self, event, ...)
 local eventWasHandled = false
 for i, item in ipairs(_V.Events) do
  if item.eventName == event then
  eventWasHandled = true

  local t = type(item.func)

  if t == "function" then
    item.func(self, event, ...)

  elseif t == "nil" then
    print("Notice: Event '" .. event .. "' was subscribed to, but not assigned any action.")
    print("Warning: function AST_RegisterEvent(frame, eventName, func)")
    print("  - Encountered data type for event function other than 'function' or 'nil'.")
    print("    Type: " .. t .. ", Value: " .. tostring(item.func) .. ".")
 if not eventWasHandled then
  print("Warning: AST_MainEventHandler(self, event, ...)")
  print(".  - Event '" .. event .. "' was fired, but not handled because it is unrecognised.")
  print("  - If you see this message, you might want to create handlers to deal with those events.")

My question is: Why is there no payload/is there anything that I am doing wrong? I can't find anything online regarding this event than type and text should be the payload for this event.

Seerah 06-02-20 07:09 PM

Where is your frame:OnEvent() part?

Fizzlemizz 06-02-20 08:13 PM

Have you tried printing the event sent to AST_Event_LUAWarning just in case you have somehow managed to AST_RegisterEvent() another event with no payload to that function association?

From the /API documents:



        LiteralName = LUA_WARNING

        warnType, Type = number, Nilable = false
        warningText, Type = string, Nilable = false

AreGee 06-02-20 08:55 PM

Wow! I seriously didn't expect to get answers that fast! Thank you!

Regarding printing the name of the event, I just printed the value that is passed in the event parameter. I do indeed get the correct event name, LUA_WARNING.

I also tried to do a:


That prints '0 (null)'.

The fact I do get a number and a string (nil - abscence of a string rather) like I am expecting makes me think Blizzard is hiding the information on purpose, but that does sound weird to me. Everything works perfectly for any other event, so I don't understand what is going on

EDIT: I just noticed in your comment that it does say that neither of the values is nilable... That makes this even weirder.

Here is the frame:OnEvent() part (sorry I didn't think it was important since the correct function does get called:


local function AST_CreateWindowFrame()
 _V.MainWindowFrame = CreateFrame("Frame", _V.C.AddOnName, UIParent)

 local frame = _V.MainWindowFrame
 frame:SetScript("OnEvent", _V.F.MainEventHandler)

 local RegEvt = _V.F.RegisterEvent

 RegEvt(frame, "ADDON_ACTION_BLOCKED", nil)
 RegEvt(frame, "ADDON_ACTION_FORBIDDEN", nil)
 RegEvt(frame, "LUA_WARNING", AST_Event_LUAWarning)
 RegEvt(frame, "SAVED_VARIABLES_TOO_LARGE", nil)
 RegEvt(frame, "ADDONS_UNLOADING", nil)

 RegEvt(frame, "ADDON_LOADED", AST_Event_AddOnLoaded)

 RegEvt(frame, "PLAYER_ENTERING_WORLD", AST_Event_PlayerEnteringWorld)

 RegEvt(frame, "AUCTION_HOUSE_SHOW", nil)
 RegEvt(frame, "AUCTION_HOUSE_CLOSED", nil)
 frame:SetWidth(_V.F.GetConfigItem("MainFrame Width"))
 frame:SetHeight(_V.F.GetConfigItem("MainFrame Height"))
 frame:SetPoint("CENTER", UIParent, "CENTER")

 frame.skeleton = frame:CreateTexture("AuctionScanner_Skeleton", "BORDER")
-- frame.skeleton:SetTexture("Interface/AUCTIONFRAME/AuctionHouseBackgrounds")
-- local top, bottom, left, right = 0.39, 0.79, 0.18, 0.47
-- frame.skeleton:SetTexCoord(left, top, left, bottom, right, top, right, bottom)
 frame.skeleton:SetColorTexture(0, 0, 0, 0.25)

 frame.title = frame:CreateFontString("AuctionScanner_Title", "OVERLAY", "GameFontNormal")
 frame.title:SetPoint("TOP", 0, 0)
 frame.title:SetText("Auction Scanner Tool")
 -- Make sure you can only run this function ONCE --
 _V.F.CreateWindowFrame = _V.F.dummy

Fizzlemizz 06-02-20 09:07 PM


local function AST_Event_LUAWarning(self, event, ...)

or possibly:

local function AST_Event_LUAWarning(self, event, ...)
        local warnType, warningText = ...
        if warnType == LUA_WARNING_TREAT_AS_ERROR -- 0
                print("Warning: LUA_WARNING, type: " .. tostring(warnType) .. ", text: " .. warningText)

A warnType of 0 appears to mean a script error rather than one coming from the game engine.

AreGee 06-02-20 10:06 PM

Thank you for pointing me in the right direction!

I think you are right, although the function HandleLuaWarning(...) did not do anything visible at all. It did not stop execution of the script either, so it is definitely a valid function.

I will leave in your modified code for now as it seems that you are right that the code 0 is a script error. Now I need to locate where I put in those mistakes... I think I put them in on purpose but I don't remember where, lol.


A bit of research reveals the HandleLuaWarning function:


function HandleLuaWarning(warnType, warningMessage)
        local cvarName = "scriptWarnings";
        if ( warnType == LUA_WARNING_TREAT_AS_ERROR ) then
                cvarName = "scriptErrors";

        DisplayMessageInternal(cvarName, warnType, warningMessage, MESSAGE_TYPE_WARNING);

So it seems all you need to do is your first suggestion to only call the function to handle the error/warning as the test is done in there anyway.

Either way, a warning message of nil is not much of help anyway.

Also, I found that the reason I never get any error messages no matter why, apart from this problem, is because WoW does not display script errors per default.

It can be turned on by the following, but I assume this is not new to anyone here:


/console scriptErrors 1
It was a script error, by the way. A part that I left out where I copy pasted and forgot to change the name of a variable made me call a function from nil.

I have a theory that script errors are treated like they are (0 (null)) because you can enable them like above to have the game show you the error message anyway. After all the name is LUA_WARNINGS, not -ERRORS.

My final version, for completeness:


local function AST_Event_LUAWarning(self, event, ...)
 local warnType, warningText = ...
 if warnType == LUA_WARNING_TREAT_AS_ERROR then
  print("ERROR: To see errors, type '/console scriptErrors 1' in the chat window, then reload your AddOn.")
  print("Warning: " .. event .. ", type: " .. tostring(warnType) .. ", text: " .. tostring(warningText))

All times are GMT -6. The time now is 08:22 AM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI