Quantcast
Another Slash Command - WoWInterface
Thread Tools Display Modes
05-24-10, 08:49 PM   #1
Sinaris
A Wyrmkin Dreamwalker
 
Sinaris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 55
Another Slash Command

Sorry for my bad english in this post, but i am a german guy. So i hope you will understand me :9

Okay. Here is my addon:


krahlog.lua

Code:
local function klog(args)

if type(KRAHLog_raidmembers) ~= "table" then
	KRAHLog_raidmembers = {}
end

local timestamp = date("%d.%m.%y %H:%M:%S")
local timestampLog = date("%m/%d/%y")

KRAHLog_raidmembers[timestamp] = {}

	for i=1, 40 do
		if UnitExists("raid"..i) then
			local LogPlayerID = i;
			local LogDate = timestampLog;
			local LogUnitClass = UnitClass("raid" .. i);
			local LogUnitName = UnitName("raid" .. i);
			--local _, LogUinitRace = UnitRace("raid" .. i);

			KRAHLog_raidmembers[timestamp][i] = LogPlayerID .." ".. LogDate .." ".. LogUnitClass .." ".. LogUnitName
		end
	end
end


SlashCmdList["SaveRaidMembers_SlashCommand"] = klog
SLASH_SaveRaidMembers_SlashCommand1 = "/klog"

And the saved variables looks like:

Code:
KRAHLog_raidmembers = {
    "1 12/5/2010 Mage Sinaris", --[1]
}
So my question is, is there any way do add another slashcommand to clean up the saved variables?
I have do delete it by hand, and that is not in my opinion

I have to:

Code:
"/klog save"
to save the current raid player in the saved variables


Code:
"klog delete"
cleans up the saved variables like this:

Code:
KRAHLog_raidmembers = {
}
i am not a pro in lua. So i hope you can help me.
  Reply With Quote
05-25-10, 07:29 AM   #2
Sinaris
A Wyrmkin Dreamwalker
 
Sinaris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 55
Okay. I was working on it, but i does not work

Here is my current code snipped:

Code:
function saveLogfile()
	print("Logfile saved");
end

function deleteLogfile()
	print("Logfile deleted");
end


SLASH_RAIDLOG1, SLASH_RAIDLOG2 = '/rlog', '/raidlog';
local function handler(msg, editbox)
	if msg == 'delete' then
		deleteLogfile();
	else
		saveLogfile();
	end
end

SlashCmdList["RAIDLOG"] = handler;

How can i add my code that i posted abouve, that this addon save and delete some variables ?
  Reply With Quote
05-25-10, 07:36 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,641
I assume you have tables listed in your TOC SavedVariables or SavedVariablesPerCharacter line ?

If so, the game automatically saves the values you store in those tables when you log out. And automatically loads them when you log in.

The simplest way to clear the table is to set it to {}.

So if your SavedVariable table was MySavedTable then you would do MySavedTable = {} to clear out the contents ready for adding new data to.

When you want to write to the table you would then do
MySavedtable = MySavedTable or {}
to use the loaded table or create a new one if it doesn't exist yet.

Then whatever you add to it will get saved. Remember though that if you wish to add another table to it you may need to repeat the process above for the sub table.
EG. MySavedTable[subTable] = MySavedTable[subTable] or {}

Otherwise simply writing MySavedTable.SavedVariable = SomeValue and MySavedTable[subTable].SubTableVariable = AnotherValue will mean it will get written to the WTF file.
__________________
  Reply With Quote
05-25-10, 07:41 AM   #4
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,641
Also, looking at your code I think you may want to change things slightly there:


Code:
local function handler(msg)
       msg = string.lower(msg);
       local args = {};
       for word in string.gmatch(msg,"[^%s]+") do
            table.insert(args,word);
       end
       if ( args[1] == "delete" ) then
          -- delete stuff here
       end
end

SLASH_RAIDLOG1, SLASH_RAIDLOG2 = '/rlog', '/raidlog';
SlashCmdList["RAIDLOG"] = handler;
__________________
  Reply With Quote
05-25-10, 07:55 AM   #5
Sinaris
A Wyrmkin Dreamwalker
 
Sinaris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 55
Okay. I will try it.

But how can i delete the strings?

Code:
KRAHLog_raidmembers = {
	["25.05.10 14:44:16"] = {
		"1 05/25/10 Death Knight Baalsabar", -- [1]
		"2 05/25/10 Paladin Taschy", -- [2]
		"3 05/25/10 Warrior Fateoflestat", -- [3]
		"4 05/25/10 Paladin Rögnvaldr", -- [4]
		"5 05/25/10 Druid Cielaroque", -- [5]
		"6 05/25/10 Rogue Maxîros", -- [6]
		"7 05/25/10 Hunter Fiatteen", -- [7]
		"8 05/25/10 Druid Muschka", -- [8]
		"9 05/25/10 Warlock Eawin", -- [9]
		"10 05/25/10 Shaman Kieras", -- [10]
		"11 05/25/10 Paladin Dale", -- [11]
		"12 05/25/10 Warrior Natias", -- [12]
	},
}
Thats in tha saved variables.
I will delete this subtable:

Code:
	["25.05.10 14:44:16"] = {
		"1 05/25/10 Death Knight Baalsabar", -- [1]
		"2 05/25/10 Paladin Taschy", -- [2]
		"3 05/25/10 Warrior Fateoflestat", -- [3]
		"4 05/25/10 Paladin Rögnvaldr", -- [4]
		"5 05/25/10 Druid Cielaroque", -- [5]
		"6 05/25/10 Rogue Maxîros", -- [6]
		"7 05/25/10 Hunter Fiatteen", -- [7]
		"8 05/25/10 Druid Muschka", -- [8]
		"9 05/25/10 Warlock Eawin", -- [9]
		"10 05/25/10 Shaman Kieras", -- [10]
		"11 05/25/10 Paladin Dale", -- [11]
		"12 05/25/10 Warrior Natias", -- [12]
	},
That means, whe i type "/rlog delte" in my chat it delete all the subtables after the logout.
  Reply With Quote
05-25-10, 08:31 AM   #6
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,641
Yes that will empty the table in its entirety. Your WTF file after typing /rlog delete will be

Code:
KRAHLog_raidmembers = {
}
if you want to only remove certain segments

EG:

Code:
KRAHLog_raidmembers = {
	["25.05.10 14:44:16"] = {
		"1 05/25/10 Death Knight Baalsabar", -- [1]
		"2 05/25/10 Paladin Taschy", -- [2]
		"3 05/25/10 Warrior Fateoflestat", -- [3]
		"4 05/25/10 Paladin Rögnvaldr", -- [4]
		"5 05/25/10 Druid Cielaroque", -- [5]
		"6 05/25/10 Rogue Maxîros", -- [6]
		"7 05/25/10 Hunter Fiatteen", -- [7]
		"8 05/25/10 Druid Muschka", -- [8]
		"9 05/25/10 Warlock Eawin", -- [9]
		"10 05/25/10 Shaman Kieras", -- [10]
		"11 05/25/10 Paladin Dale", -- [11]
		"12 05/25/10 Warrior Natias", -- [12]
	},
	["26.05.10 14:45:00"] = {
		"1 05/26/10 Death Knight Baalsabar", -- [1]
		"2 05/26/10 Paladin Taschy", -- [2]
		"3 05/26/10 Warrior Fateoflestat", -- [3]
		"4 05/26/10 Paladin Rögnvaldr", -- [4]
		"5 05/26/10 Druid Cielaroque", -- [5]
		"6 05/26/10 Rogue Maxîros", -- [6]
		"7 05/26/10 Hunter Fiatteen", -- [7]
		"8 05/26/10 Druid Muschka", -- [8]
		"9 05/26/10 Warlock Eawin", -- [9]
		"10 05/26/10 Shaman Kieras", -- [10]
		"11 05/26/10 Paladin Dale", -- [11]
		"12 05/26/10 Warrior Natias", -- [12]
	},
}
And you only wanted to delete segment ["25.05.10 14:44:16"] then you might want to look into how tremove works as the example I gave you will wipe it out totally.

Which reminds me .. the other way to wipe a table is to actually use the command wipe(tableName).
__________________
  Reply With Quote
05-25-10, 09:14 AM   #7
Sinaris
A Wyrmkin Dreamwalker
 
Sinaris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 55
Code:
local function handler(msg)
       msg = string.lower(msg);
       local args = {};
       for word in string.gmatch(msg,"[^%s]+") do
            table.insert(args,word);
       end
       if ( args[1] == "delete" ) then
          KRAHLog_raidmembers = {}
       end
end

SLASH_RAIDLOG1, SLASH_RAIDLOG2 = '/rlog', '/raidlog';
SlashCmdList["RAIDLOG"] = handler;
Mhm, but its not working. I am cunfused about LUA, sorry (
  Reply With Quote
05-25-10, 09:24 AM   #8
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,641
Hmm, well the last 2 lines I got from your code as I assumed the slash command function was being reached.

This is how I code for slash commands if my addon name is called ScrollingWatchFrame

I am assuming that your TOC file contains KRAHLog_raidmembers as a saved variable table. Add a print("blah text") line to make sure it gets to where you want.

Code:
local function ValidateSlashCommand(msg)
       msg = string.lower(msg);
       local args = {};
       for word in string.gmatch(msg,"[^%s]+") do
            table.insert(args,word);
       end
       if ( args[1] == "delete" ) then
          print("Deleting the contents of KRAHLog_raidmembers which currently has the value of ", KRAHLog_raidmembers);
          KRAHLog_raidmembers = {}
       end
end

Code:
SLASH_ScrollingWatchFrameCmd1 = '/swf';

SlashCmdList['ScrollingWatchFrameCmd'] = ValidateSlashCommand;
That print line I added should show that you reached that part of the function and what the current value of that table is. It should say something like table:123423 which tells us it is a table whether it is empty or not.

You may have to change the yellow items to reflect your addon but that should all work the way you want. If it doesn't try the wipe(KRAHLog_raidmembers) instead and see if that works. I am doing this from memory but I do know wipe(table) works as I use it in one of my own addons.

The function converts what you type into lower case so the case is not an issue here.

With my example /swf delete should trigger the slash command test and empty the table. Simply changing the yellow items to your addons values should be enough.
__________________

Last edited by Xrystal : 05-25-10 at 09:30 AM.
  Reply With Quote
05-25-10, 09:29 AM   #9
Sinaris
A Wyrmkin Dreamwalker
 
Sinaris's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 55
Yes.
My toc file hast:

## SavedVariables: KRAHLog_raidmembers

at the top of the line
  Reply With Quote
05-25-10, 05:54 PM   #10
numein
A Cyclonian
 
numein's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2009
Posts: 43
I'm not too familiar with Lua yet, but if I understood what you want to do with your addon, this should do it (I only changed your slash command, the rest of the code can stay as is):
Code:
...

SlashCmdList["SaveRaidMembers_SlashCommand"] = function(str)
	if (str == 'delete') then
		KRAHLog_raidmembers = {}
		print('|cff00aaff<krahlog> Data deleted.|r')
	elseif (str == 'save') then
		klog()
		print('|cff00aaff<krahlog> Data saved.|r')
	else
		print('<krahlog> To save current data type: /klog save')
		print('<krahlog> To delete all saved data type: /klog delete')
	end
end
SLASH_SaveRaidMembers_SlashCommand1 = "/klog"
If u type /klog in chat it will just print you a message to use /klog save, /klog delete.
On /klog save it will call your klog() function to save the data, and print out a msg in chat that it's saved.
On /klog delete it will empty the table in SavedVars.

Hope it helps.
  Reply With Quote
05-25-10, 07:51 PM   #11
upyursh
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 32
If you are wanting to clear the sub tables then you will need to pass the ID for the table in something like this;

Code:
local function ValidateSlashCommand(msg)
       msg = string.lower(msg);
       local args = {};
       for word in string.gmatch(msg,"[^%s]+") do
            table.insert(args,word);
       end
       if ( args[1] == "delete" and args[2] and args[3]) then
          raid_id = args[2] . " " . args[3]
          print("Deleting the contents of KRAHLog_raidmembers[raid_id] which currently has the value of ", KRAHLog_raidmembers[raid_id]);
          KRAHLog_raidmembers[raid_id] = nil
       end
end
you would then run something

/klog delete 25.05.10 14:44:16

thats completely untest but basically u define the ID you want and then set it to nil to remove it from the main table.

Ideally you would have a better ID, rather than using the date/time.

a better structure might be;

Code:
KRAHLog_raidmembers = {
  [0] = {
    [date] = "25.05.10 14:44:16",
    [raiders] = {
      "1 05/25/10 Death Knight Baalsabar", -- [1]
      "2 05/25/10 Paladin Taschy", -- [2]
      "3 05/25/10 Warrior Fateoflestat", -- [3]
      "4 05/25/10 Paladin Rögnvaldr", -- [4]
      "5 05/25/10 Druid Cielaroque", -- [5]
      "6 05/25/10 Rogue Maxîros", -- [6]
      "7 05/25/10 Hunter Fiatteen", -- [7]
      "8 05/25/10 Druid Muschka", -- [8]
      "9 05/25/10 Warlock Eawin", -- [9]
      "10 05/25/10 Shaman Kieras", -- [10]
      "11 05/25/10 Paladin Dale", -- [11]
      "12 05/25/10 Warrior Natias", -- [12]
    },
  },
  [1] = {
    [date] = "26.05.10 14:45:00",
    [raiders] = {
      "1 05/26/10 Death Knight Baalsabar", -- [1]
      "2 05/26/10 Paladin Taschy", -- [2]
      "3 05/26/10 Warrior Fateoflestat", -- [3]
      "4 05/26/10 Paladin Rögnvaldr", -- [4]
      "5 05/26/10 Druid Cielaroque", -- [5]
      "6 05/26/10 Rogue Maxîros", -- [6]
      "7 05/26/10 Hunter Fiatteen", -- [7]
      "8 05/26/10 Druid Muschka", -- [8]
      "9 05/26/10 Warlock Eawin", -- [9]
      "10 05/26/10 Shaman Kieras", -- [10]
      "11 05/26/10 Paladin Dale", -- [11]
      "12 05/26/10 Warrior Natias", -- [12]
    },
  },
}
but that's up to u i guess

I think your best option though is to look into a UI component that will give you a list of raids and a button to click to delete (which stores the ID etc in it)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Another Slash Command

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