Thread Tools Display Modes
05-07-22, 10:52 AM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
First install & not printing to screen/showing frame

I was debugging TSM_StringConverter and found an oddity. If the saved variables are wiped, or the addon is freshly installed, the GUI and chat messages are not displayed. If I /reload my UI and don't change any of settings, the slash commands work.

Further, the slash commands do not work at all during a fresh installation. It is like they aren't being initialized when they are called. The test prints in PEW are not doing anything during the first install either. They work after a /reload.

And I don't know why I am getting this behaviour.
Code:
local title, addon = ...
local L = addon.L
local gui = LibStub("AceGUI-3.0")

local text_store = "" -- store the edit box text
local main_frame

addon.frame = CreateFrame("Frame")
addon.frame:RegisterEvent("PLAYER_LOGIN")
addon.frame:RegisterEvent("PLAYER_ENTERING_WORLD")
addon.frame:SetScript("OnEvent", function(self, event, ...)
    addon[event](self, ...)
end)

local function PrintCommands()
    print(L["/tsmsc slash commands:"])
    print("  " .. HELP_LABEL:lower() .. " " .. L["or ? prints this menu."])
    print("  " .. L["login toggles showing the frame when you first log into WoW."])
    print("  " .. L["reload toggles showing the frame when you reload your UI."])
    print("  " .. L["message toggles displaying this message when you log into WoW."])
    print("  " .. L["Any other entry toggles the frame"])
    print(L["Example: /tsmsc login"])
end

local function ToggleFrame()
    if main_frame and main_frame:IsShown() then return end

    main_frame = main_frame or gui:Create("Frame")
    main_frame:SetTitle(L["TSM String Converter"])
    main_frame:SetStatusText(L["TradeSkillMaster itemID String Fixer"])
    main_frame:SetCallback("OnClose", function(widget)
        text_store = ""
        gui:Release(widget)
    end)
    main_frame:SetLayout("Flow")

    local edit_box = gui:Create("MultiLineEditBox")
    edit_box:SetLabel(L["Insert itemIDs"])
    edit_box:SetRelativeWidth(1.0)
    edit_box:SetNumLines(25)
    edit_box:SetMaxLetters(0) -- no limit to the number of characters entered
    edit_box:DisableButton(true) -- disables the "Okay" button
    edit_box:SetCallback("OnTextChanged", function(widget, event, text)
        edit_box:SetLabel(L["Insert itemIDs"])
        text_store = text
    end)
    main_frame:AddChild(edit_box)

    local button = gui:Create("Button")
    button:SetText(CONVERT)
    button:SetRelativeWidth(1.0)
    button:SetCallback("OnClick", function()
        -- strip out all spaces, just in case
        text_store = text_store:trim()
        text_store = string.gsub(text_store, " ", "")

        -- break text_store entirely, and fix it (credit to krowbar71 on the Wowinterface forums)
        text_store = string.gsub(string.gsub(text_store, "[iI]:", ""), "(%d+)", "i:%1")

        print("|cff32cd32TSMSC: |r" .. DONE_EDITING)

        edit_box:SetText(text_store)
        edit_box:HighlightText()
        edit_box:SetFocus()
        edit_box:SetLabel(DONE_EDITING)
    end)
    main_frame:AddChild(button)
end -- end of ToggleFrame()

-- create and handle slash command
SLASH_TSMSC1 = L["/tsmsc"]
SlashCmdList["TSMSC"] = function(msg, editBox) -- the edit box that originated the command, not the input field for itemIDs
    msg = msg and strtrim(strlower(msg))

    if msg == L["message"] then
        TSMSC_DB.showMessage = not TSMSC_DB.showMessage
        if TSMSC_DB.showMessage then
            print(L["TSMSC: showing help menu during log in."])
        else
            print(L["TSMSC: no help menu during log in."])
        end

    elseif msg == L["login"] then
        TSMSC_DB.login = not TSMSC_DB.login
        if TSMSC_DB.login then
            print(L["TSMSC: will show the frame during log in."])
        else
            print(L["TSMSC: won't show the frame during log in."])
        end

    elseif msg == L["reload"] then
        TSMSC_DB.reload = not TSMSC_DB.reload
        if TSMSC_DB.reload then
            print(L["TSMSC: will show the frame when you relod your UI."])
        else
            print(L["TSMSC: won't show the frame when you reload your UI."])
        end

    elseif msg == HELP_LABEL:lower() or msg == L["?"] then
        PrintCommands()
        
    else
        if main_frame and main_frame:IsShown() then
            text_store = ""
            main_frame:Release()
        else
            ToggleFrame()
        end
    end
end

function addon:PLAYER_LOGIN()
    addon.frame:UnregisterEvent("PLAYER_LOGIN")

    if TSMSC_DB == nil then TSMSC_DB = {} end
    if TSMSC_DB.login == nil then TSMSC_DB.login = true end
    if TSMSC_DB.reload == nil then TSMSC_DB.reload = false end
    if TSMSC_DB.showMessage == nil then TSMSC_DB.showMessage = true end
end

function addon:PLAYER_ENTERING_WORLD(isInitialLogin, isReloadingUI)
    print("Initial login:", isInitialLogin)
    print("UI reload:", isReloadingUI)

    if isInitialLogin then
        if TSMSC_DB.login then
            ToggleFrame()
        end

        if TSMSC_DB.showMessage then
            PrintCommands()
        end
    end

    if isReloadingUI then
        if TSMSC_DB.reload then
            ToggleFrame()
        end
    end
end
  Reply With Quote
05-07-22, 04:58 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
I might be missing something obvious but .. is there a chance that PLAYER_ENTERING_WORLD is triggering before PLAYER_LOGIN meaning that the .login and .reload flags don't get set until the reload, or if PLAYER_LOGIN is triggered first.

Outside of that old chestnut which may or may not have been fixed since I noticed that problem several years back I can't see anything else myself.
__________________
  Reply With Quote
05-07-22, 09:03 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
What is TSM_StringConverter and is it LOD?

If it is, maybe it is loaded by the "host" addon at PLAYER_LOGIN meaning that event will have already passed before TSM_StringConverter is loaded... or some shenanigans like that.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
05-07-22, 09:57 PM   #4
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Originally Posted by Xrystal View Post
I might be missing something obvious but .. is there a chance that PLAYER_ENTERING_WORLD is triggering before PLAYER_LOGIN meaning that the .login and .reload flags don't get set until the reload, or if PLAYER_LOGIN is triggered first.

Outside of that old chestnut which may or may not have been fixed since I noticed that problem several years back I can't see anything else myself.
That could be it, yes. I'll try ADDON_LOADED instead.

Originally Posted by Fizzlemizz View Post
What is TSM_StringConverter and is it LOD?

If it is, maybe it is loaded by the "host" addon at PLAYER_LOGIN meaning that event will have already passed before TSM_StringConverter is loaded... or some shenanigans like that.
It isn't LOD. It converts player-created batches of itemIDs from TradeSkillMaster3 format 1234,2345,3456 to TradeSkillMaster4 format i:1234,i:2345,i:3456. The addon does not depend on TSM to be installed, although if a user does not have TSM, this addon isn't going to be useful.
  Reply With Quote
05-08-22, 12:22 AM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
On the face of it it looks like it should work but what's here obviously isn't the entire addon.

If you cut the addon down (create a test addon) to just this code and it works then the problem is elsewhere.

Things like adding events (event functions) to the addon table is possibly prone to having them overwritten somewhere else (another .lua module).
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
05-08-22, 12:45 AM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Here is the full addon, retail WoW version.
Attached Files
File Type: zip TSM_StringConverter.zip (66.9 KB, 63 views)
  Reply With Quote
05-08-22, 08:58 AM   #7
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
First install seemed to work. GUI popped up, PrintCommands() ran, slash command worked, events were processed and in expected order.

Worked just the same after exiting and deleting the SV file.

And again after logging on to a different character...
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-08-22 at 09:03 AM.
  Reply With Quote
05-08-22, 11:08 AM   #8
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I was about to test again, after wiping my saved variables. If you saw it working, that's a good sign. Apparently ADDON_LOADED does fire before PEW, but PLAYER_LOGIN may not. I went with the Wowpedia.org event loading process, albeit before I posted my question, I was not handling the event args correctly.

For some reason, I had this in my head, which clearly is not correct:
Code:
function MyAddOn:EventHandler(event, ...)
I am not sure where I got event from as an argument, but that was debunked by my PEW print statements. I was doing the same in my original ADDON_LOADED, which is why I switched to PLAYER_LOGIN.
  Reply With Quote
05-08-22, 11:49 AM   #9
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
If PLAYER_LOGIN didn't fire until after PEW then all my addons would be broken. It should fire only once after all inital ADDON_LOADEDs have happened and before PEW.

Which might have caused a propblem if at some stage you registered ADDON_LOADED and PLAYER_LOGIN but unregistered PLAYER_LOGIN at ADDON_LOADED.

What you get in your event functions is entirely dependant on what your OnEvent script sends them. You may have seen code from someone that sends the event and payload (I tend to send the frame "self" to the functions, but that's me).

Edit: For giggles, I changed the code from ADDON_LOADED to PLAYER_LOGIN, reset and everything worked fine as well.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-08-22 at 01:28 PM.
  Reply With Quote
05-09-22, 05:29 AM   #10
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Oops .. it wasn't the loading order of PLAYER_LOGIN and PLAYER_ENTERING_WORLD I was remembering but VARIABLES_LOADED. We used to use the last one in nUI and had intermittent issues so switched to PLAYER_ENTERING_WORLD or PLAYER_LOGIN as needed to fix those issues.

Had to search the nUI archives to refresh my memory on what I was recalling from 10+ years ago :chuckle:
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » First install & not printing to screen/showing frame

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off