Thread Tools Display Modes
12-09-09, 06:41 PM   #1
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
How to use CVars in functions?

So with the new changes to 3.3 there are new cvars for

nameplateShowEnemy
nameplateShowEnemyPets
nameplateShowEnemyGuardians
nameplateShowEnemyTotems
nameplateShowFriend
nameplateShowFriendPets
nameplateShowFriendGuardians
nameplateShowFriendTotems
nameplateAllowOverlap

Have been incorporated.

I'm fairly new to scripting Lua and I'm not sure how to use the GetCVar an SetCvar API functions.

Since most CVars return a "1" or "0" they're not considered booleans. I saw the GetCVarBool() function and I'm not sure exactly how to incorporate it.

For example I used to have a saved variable returning true or false for a toggle in my ace 3 options:

Code:
totems = {
	order = 1,
	type = "toggle",
	name = L["Show Totems"],
	desc = L["Toggles the showing and hiding of All totem nameplates."],
	get = function() return self.db.profile.showtotems end,
	set = function(info,val) 
		self.db.profile.showtotems = not self.db.profile.showtotems
		if self.db.profile.showtotems then return print("-->>Totem Nameplates are now |cff00ff00ON!|r<<--") else return print("-->>Totem Nameplates are now |cffff0000OFF!|r<<--") end
		end
},
Could it be simplified to:
Code:
totems = {
	order = 1,
	type = "toggle",
	name = L["Show Totems"],
	desc = L["Toggles the showing and hiding of All totem nameplates."],
	get = function() return GetCVarBool("nameplateShowEnemyTotems") end,
	set = function(info,val) 
		if GetCVarBool("nameplateShowEnemyTotems") then
			SetCVar("nameplateShowEnemyTotems", 0, "scriptCVar")
		else
			SetCVar("nameplateShowEnemyTotems", 1, "scriptCVar")
		end
	end
},
??

I tried this and I get the toggle to show accurately, however changing the value for it in the options doesn't seem to set the CVar.

Where am I failing?
  Reply With Quote
12-09-09, 07:51 PM   #2
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
AFAIK, the interface options will only reflect cvars on reloadui.
  Reply With Quote
12-09-09, 08:01 PM   #3
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Katae View Post
AFAIK, the interface options will only reflect cvars on reloadui.
Should I use the cvar method? and just set a saved variable to w/e the cvar of the player is?
  Reply With Quote
12-09-09, 08:07 PM   #4
Katae
A Cobalt Mageweaver
AddOn Author - Click to view addons
Join Date: Jun 2007
Posts: 208
Your second code would work ok, but you don't need "scriptCVar" there.

Edit:
Code:
set = function()
    SetCVar("nameplateShowEnemyTotems",abs(GetCVar("nameplateShowEnemyTotems")-1))
end

Last edited by Katae : 12-09-09 at 08:16 PM.
  Reply With Quote
12-09-09, 08:23 PM   #5
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Katae View Post
Your second code would work ok, but you don't need "scriptCVar" there.

Edit:
Code:
set = function()
    SetCVar("nameplateShowEnemyTotems",abs(GetCVar("nameplateShowEnemyTotems")-1))
end
Kk that makes more sense, however what should I have my get function to?
  Reply With Quote
12-09-09, 08:30 PM   #6
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
CombatNames is coded to change CVAR for enemy nameplate visibility in/out of combat. You can use that as an example.
  Reply With Quote
12-09-09, 08:47 PM   #7
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by ChaosInc View Post
CombatNames is coded to change CVAR for enemy nameplate visibility in/out of combat. You can use that as an example.
Mmm nothing in that helps my problem >.>, but ty.
  Reply With Quote
12-14-09, 03:06 AM   #8
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by suicidalkatt View Post
I tried this and I get the toggle to show accurately, however changing the value for it in the options doesn't seem to set the CVar.
Still unsure of a good method for giving an alternate yet Cvar accurate return for Ace 3 Options.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to use CVars in functions?


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