Thread Tools Display Modes
Prev Previous Post   Next Post Next
10/22/17, 11:20 AM   #1
Kronn8
Join Date: Oct 2017
Posts: 5
Question [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!

Last edited by Kronn8 : 10/22/17 at 11:32 AM. Reason: Thread solved
  Reply With Quote
 

ESOUI » Developer Discussions » Lua/XML Help » Unable to call a function


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