Thread Tools Display Modes
07-27-06, 03:25 PM   #1
Whissler
A Defias Bandit
Join Date: Jul 2006
Posts: 2
Question About Lua Tables....

Okay I am working on a modified version of Hob_DKP for my guild. Were doing some very unique things with DKP that require me to not only post the DKP value of an item but a certificaiton level based on standards we have. Anyways.......here is what I have right now.....

Code:
	local Eg_Cert_Excep = nil;
	local RC1 = "Raid Gear 1";
	local RC2 = "Raid Gear 2";
	local RC3 = "Raid Gear 3";
	local EG_R2_Item_1 = "Truefaith Vestments";
	local EG_R2_Item_2 = "Virtuous Skirt";
	local Eg_R2_Item_3 = "Titanic Leggings";
	local Eg_R2_Item_4 = "Lionheart Helm";
	local EG_R2_Item_5 = "Band of Rumination";
	local EG_R2_Item_6 = "Fordring's Seal";
	local EG_R2_Item_7 = "Deep River Cloak";

	if HDKP_EG_ItemName == EG_Item_1 or
				HDKP_EG_ItemName == EG_R2_Item_1 or
				HDKP_EG_ItemName == EG_R2_Item_2 or
				HDKP_EG_ItemName == EG_R2_Item_3 or
				HDKP_EG_ItemName == EG_R2_Item_4 
	then
				Eg_Cert_Excep = RC2;
	end
	
	if HDKP_EG_ItemName == EG_R2_Item_5 or
				HDKP_EG_ItemName == EG_R2_Item_6 or
				HDKP_EG_ItemName == EG_R2_Item_7
	then
				Eg_Cert_Excep = RC1;
	end

HDKP_EG_ItemName is a variable that contains the name of the item in question.

Right now I have each item that I want to exception listd out as their own variable.......

Code:
	local EG_R2_Item_1 = "Truefaith Vestments";
	local EG_R2_Item_2 = "Virtuous Skirt";
	local Eg_R2_Item_3 = "Titanic Leggings";
	local Eg_R2_Item_4 = "Lionheart Helm";
	local EG_R2_Item_5 = "Band of Rumination";
	local EG_R2_Item_6 = "Fordring's Seal";
	local EG_R2_Item_7 = "Deep River Cloak";
What I would like to do is move these to the localizations.lua and convert them into one big table so that my if then code doesnt need to continue to grow as the exceptions grow. And it makes it easier to manage.

I am assuming the table should look like this then........if the item name is the key and the exception I am giving them is what is currently listed as RC1, RC2, and RC3

Code:
EG_EXCEPT_DATA = {
     	["Truefaith Vestments"] = "Raid Gear 2";
	["Virtuous Skirt"] = "Raid Gear 2";
	["Titanic Leggings"] = "Raid Gear 2";
	["Lionheart Helm"] = "Raid Gear 2";
	["Band of Rumination"] = "Raid Gear 2";
	["Fordring's Seal"] = "Raid Gear 1";
	["Deep River Cloak"] = "Raid Gear 1";
 };
How do I express the following in LUA ive searched on multiple forums scoured multiple websites and I guess im stupid cause I cant figure it out.....


If HDKP_ITemName matches a KEY in EG_EXCEPT_DATA THEN I want the Variable EG_CERT_EXCEPT to get set to the string in the table associated with the match. (EXAMPLE IF IT WAS Truefaith Vestments it would be "Raid Gear 2")
  Reply With Quote
07-28-06, 10:57 AM   #2
Esamynn
Featured Artist
Premium Member
Featured
Join Date: Jan 2005
Posts: 395
Code:
EG_CERT_EXCEPT =  EG_EXCEPT_DATA[HDKP_ITemName];
If the key/value pair exists in EG_EXCEPT_DATA, then EG_CERT_EXCEPT will be the value referenced by whatever key is stored in the HDKP_ITemName variable. If the key doesn't exist, then EG_CERT_EXCEPT will be nil.

Remember that only 'nil' and 'false' evaluate to false when you are using boolean comparision statements (ie, if, or, and, not). All other values, including 0 and "" evaluate to true in Lua.

Last edited by Esamynn : 07-28-06 at 10:57 AM. Reason: corrected variable name
  Reply With Quote
07-28-06, 02:27 PM   #3
Whissler
A Defias Bandit
Join Date: Jul 2006
Posts: 2
When I get home if this works I am gong to kiss you all over!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Question About Lua Tables....


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