"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) 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 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! |
Code:
local function HasActiveTotem() |
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() |
It's true, not sure why I wrote what I did... :'(
|
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 I think there is no direct way to check for active totems, one has to use Code:
if name == "" |
Code:
local frame = CreateFrame("frame") There is something wrong with that code, and I'm too tired to find the error. |
1. Data that is static/constant does not need to be called each time, i.e. if you know that the player must be a specific class then you don't need to check for it each time inside the routine, instead make it so the routine does not load or run at all if the class is wrong. Unlike when we are checking other targets, the player can only be one class when he logs in.
2. When a frame has several events registered, the function you write runs each time one of the events is received by the game from the server, meaning if you have that code it will run each time you get out of combat, enter combat, power is restored, e.g. This means the "event" will always have one value at a time. 3. It's a good habit to try split up things, like when I know I will run the same code several times I put that code in it's own function and call it when I need it, the idea of CheckTotems below is to run trough the 4 totems, if it's spawned to show the frame, if not then hide it. But since we can only do this outside of combat, at the begining there is the combat check, if the variable inCombat is set then it means we are in combat and we can't work with the frames. NOTE: not all frames are like this, I don't know the addon and such, but if you like try disable the return part so the frames are shown or hidden during combat too, if it works then it's just nicer isn't it? 4. getglobal and _G are the same 5. select will select the n-th value we got 'local class, enClass = UnitClass("player")' if we only want the enClass we can just do 'select(2, UnitClass("player"))' and another way to tackle these is for example "local _, enClass = ..." if you don't bother with the first one but you want the 2nd. 6. When assuming a frame exists like 't = _G["XiTimers_Timer"..i]' it's nice to first check that the object after that actually exists, before trying to run methods like t:Show(), in case it does not exist you will get an error and the addon code will fail, it's nicer for it to not fail like this. Here is my suggestion, what I think you tried to make: Code:
if select(2, UnitClass("player")) ~= "SHAMAN" then |
That's pretty inefficient, too, with numerous unnecessary extra functions and checks. I also have no idea why you're ignoring all events that occur in combat. I'd say the vast majority of totem drops/deaths/recalls occur in combat. It looks like the OP is trying to write a totem timer, which does not involve any secure frames.
Lua Code:
|
I took a shot, no clue what he was trying to do in the first place... -_-
|
Quote:
Of course I will listen to PLAYER_TOTEM_UPDATE and not to UNIT_POWER, that was just a substitute because I wasn't aware of that event's existence. That would also eliminate the need for querying the power type (and also the unitID?) :) I do want to listen to the two "entering combat events". I'm not at my home WoW installation so I can't work on the addon right now. I will update this post later. |
As the first return of GetTotemInfo is wether a totem exists or not, you don't have to check names.
The cleanest and most efficent way to do this is so: Lua Code:
You can check for each totem if you'd like, through the 1st argument in PLAYER_TOTEM_UPDATE. I made a simple totem tracking addon for my shaman about a year ago, take a look if you want: https://github.com/p3lim/Devak/blob/master/Devak.lua |
Quote:
|
Quote:
https://github.com/tekkub/wow-ui-sou...mFrame.lua#L53 |
This is misleading as mentioned above.
This code will always return true for haveTotem no matter if a totem is active or not Code:
/run for i=1,4 do print(GetTotemInfo(i)) end |
After looking at some of my own code, checking the duration also works:
Code:
for slot = 1, 4 do |
All times are GMT -6. The time now is 10:17 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI