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,929
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.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  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,929
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;
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  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,929
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).
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote

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


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