Thread Tools Display Modes
12-26-11, 02:14 PM   #1
Jonisaurus
An Aku'mai Servant
 
Jonisaurus's Avatar
Join Date: Aug 2011
Posts: 35
"GetTotemInfo" help

I'm trying to create a function that is triggered by "UNIT_POWER" and checks whether I have a totem active or not.

I'm trying to use the "GetTotemInfo" function for this, but I'm not succeeding.
There are 4 returns for this function
Code:
haveTotem, totemName, startTime, duration = GetTotemInfo(1 through 4)
here is what they do each:
http://www.wowwiki.com/API_GetTotemInfo

Only one argument (integer for each element, 1 through 4).

Now I'm using i as a variable
Code:
for i=1,4 do
for the argument, but that's not the problem.

I need help setting up a functon that checks for each element if there is ONE totem active or not, (NOTE: totemName returns "" instead of "nil" when there is no totem active).

Thank you!
  Reply With Quote
12-26-11, 03:39 PM   #2
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Code:
local function HasActiveTotem()
  local active = false
  for i = 1, 4 do
    active = active or GetTotemInfo(i)
  end
  return active
end
HasActiveTotem() would return true/false depending if there is minimum one totam active or not.
  Reply With Quote
12-26-11, 06:58 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You don't even need to store a variable. If you only want to know if any totem is active, you can return out of your function immediately as soon as you find one, without continuing to loop through the rest of the totem slots. You also don't need to explicitly return false, as a nil value is the same.

Code:
local function HasActiveTotem()
     for i = 1, 4 do
          if GetTotemInfo(i) then
               return true
          end
     end
end
  Reply With Quote
12-26-11, 09:16 PM   #4
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
It's true, not sure why I wrote what I did... :'(
  Reply With Quote
12-27-11, 04:03 AM   #5
Jonisaurus
An Aku'mai Servant
 
Jonisaurus's Avatar
Join Date: Aug 2011
Posts: 35
I think you guys made a mistake in thinking that "haveTotem" returns anything else than "true", because it doesn't. It in fact tests whether one has the TOTEM REAGENT, so if one is able to cast any totem of that school. It doesn't test for active totems.

I confirmed this ingame using this macro
Code:
/run local haveTotem, name = GetTotemInfo(1) if haveTotem then print("b") end
it always prints "b", regardless of whether I have an active totem or not. It does however not work on my druid.

I think there is no direct way to check for active totems, one has to use
Code:
if name == ""
because "name" returns nothing if there is no active totem.
  Reply With Quote
12-27-11, 05:54 AM   #6
Jonisaurus
An Aku'mai Servant
 
Jonisaurus's Avatar
Join Date: Aug 2011
Posts: 35
Code:
local frame = CreateFrame("frame")
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:RegisterEvent("PLAYER_REGEN_DISABLED")
frame:RegisterEvent("PLAYER_LOGIN")
frame:RegisterEvent("UNIT_POWER")

local function HideAndShow(self, event, ...)
	local unitId, resource = ...
	local class, classFileName = UnitClass("player")
	if unitId == "player" and resource == "MANA" and classFileName == "SHAMAN" then
		print("ABC")
		for i = 1, 4 do
			local haveTotem, name = GetTotemInfo(i)
			for o = 1,4 do
				local frame = getglobal("XiTimers_Timer"..o)
				if event == "UNIT_POWER" and name == "" and event == "PLAYER_REGEN_DISABLED" then
					frame:Show()
				else
					frame:Hide()
				end
			end
		end
	end
end

frame:SetScript("OnEvent", HideAndShow)
Okay, this does not work. Can you help me here? Please :P
There is something wrong with that code, and I'm too tired to find the error.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » "GetTotemInfo" help


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