This is the first step for slash commands. Either have this line in your initialising function or call the function there. In essence it is saying, watch for /xrga input and process it with the function ProcessSlashCommands.
Lua Code:
-- Initialise slash Commands
local function InitSlashCommands(...)
SLASH_COMMANDS["/xrga"] = ProcessSlashCommands
end
option is anything that appears after /xrga. So first we need to extract what is typed afterwards. This extraction code extracts up to 2 phrases from the command line so to speak. For example /xrga alert is one phrase 'alert' which becomes option[1]. /xrga zone kenarthi's roost is treated as two phrases 'zone' as option[1] and 'kenarthi's roost' as option[2].
It next tests to see if it finds no phrases so that #options equate to 0 or you type 'help' it lists the available options on screen.
It then processes the options it found and carries out the code to process them.
The two examples I have listed shows the 1 phrase option and 2 phrases option in action. /xrga update to generate the harvest data into a simple table for easy access bypassing the account information not needed for the addon to work. /xrga zone [zonename] uses that simplified harvest data to extract the information related to the zone requested, the current zone if none is requested and if somehow it thinks you are not in a zone it will list everything
Lua Code:
-- Process the slash commands
local function ProcessSlashCommands(option)
-- Extract Options
local options = {}
local searchResult = { string.match(option,"^(%S*)%s*(.-)$") }
for i,v in pairs(searchResult) do
if (v ~= nil and v ~= "") then
options[i] = string.lower(v)
end
end
-- Show what slash commands are available
if #options == 0 or options[1] == "help" then
CHAT_SYSTEM:AddMessage("XrysGatherer Slash Commands")
CHAT_SYSTEM:AddMessage("/xrga alert - toggle the harvest alert window")
return
end
-- Execute functionality based on user requests
-- Refresh the Harvest History table
if options[1] == "update" then
UpdateHarvestHistory()
-- Display items gatherered in the selected zone or the current zone
elseif options[1] == "zone" then
local testItem = options[2] or GetUnitZone("player")
if testItem then
ChatMsg:AddMessage(string.format("Listing history for zone: %s",testItem))
else
ChatMsg:AddMessage("Listing history for all zones")
end
for historyIndex,historyData in pairs(harvestHistory) do
for zoneIndex,zoneData in pairs(historyData) do
if testItem and string.lower(zoneIndex) == string.lower(testItem) or not testItem then
for itemIndex,itemData in pairs(zoneData) do
for indexIndex,indexData in pairs(itemData) do
ChatMsg:AddMessage('Display the appropriate information here')
end
end
end
end
end
etc...
I hope that helps you figure that part out.