ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Unable to call a function (https://www.esoui.com/forums/showthread.php?t=7422)

Kronn8 10/22/17 11:20 AM

[SOLVED] Unable to call a function
 
I feel like I'm taking crazy pills.
I'm simply trying to call a function using a slash command, but I keep getting this error when I input a command.

Entering "/fmi show" in the chat window results in this error:

Code:

user:/AddOns/FMI/FMI.lua:41: function expected instead of nil
stack traceback:
        user:/AddOns/FMI/FMI.lua:41: in function 'FMI.Command'
        EsoUI/Ingame/SlashCommands/SlashCommands_Shared.lua:71: in function 'DoCommand'
        EsoUI/Ingame/ChatSystem/SharedChatSystem.lua:1813: in function 'SharedChatSystem:SubmitTextEntry'
        EsoUI/Ingame/ChatSystem/SharedChatSystem.lua:2531: in function 'ZO_ChatTextEntry_Execute'
        ZO_ChatWindowTextEntryEditBox_Enter:3: in function '(main chunk)'
        (tail call): ?
        (tail call): ?

Below is my current lua file. I've marked the problem line in red.

Code:

----- Free My Inventory

----- Declare Core Data/Objects
FMI={}


---------------------------------Output --------------------


-------------------------------- Initialize------------------------------------

function FMI.Initialize(eventCode, addOnName)
        if(addOnName == "FMI") then
                EVENT_MANAGER:UnregisterForEvent("FMI", EVENT_ADD_ON_LOADED)
        end
end


-------------------------------- Functions------------------------------------

function FMI.showWindow()
        FMI:SetHidden(false)
        return
end

function FMI.hideWindow()
        FMI:SetHidden(true)
        return
end

function FMI.Command(options)
        if options == nil or options == "" then
                d("Please add options \"show\" or \"hide\".")
                return
        end

        cmd=string.lower(options)

        if cmd == "show" then
                d("Trying to show window...")  -- This prints successfully in the chat window.
                FMI.showWindow() --ERROR: function expected instead of nil
        elseif cmd == "hide" then
                d("Trying to hide window...")
                FMI.hideWindow()
        end
        return
end


------------------------------------------ Event Handling ----------------------------------------------

SLASH_COMMANDS["/fmi"] = FMI.Command
EVENT_MANAGER:RegisterForEvent("FMI", EVENT_ADD_ON_LOADED, FMI.Initialize)

I'm at my wit's end here. I copied the aforementioned code from an existing add-on. That add-on works, so I cannot for the life of me figure out why my copy isn't working.

Thank you in advance for any help!

Shinni 10/22/17 11:24 AM

You probably created a control called FMI in your .xml file. After the xml file is loaded the global variable FMI will refer to the control instead of the table you defined in your lua file. The control does not have a showWindow function, hence the error.

Kronn8 10/22/17 11:29 AM

Quote:

Originally Posted by Shinni (Post 32960)
You probably created a control called FMI in your .xml file. After the xml file is loaded the global variable FMI will refer to the control instead of the table you defined in your lua file. The control does not have a showWindow function, hence the error.

Thank you so much! That was the problem. I renamed the control in my .xml file, and it worked on the first try.


All times are GMT -6. The time now is 12:37 PM.

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