Need help for Addon please
Hello everyone!
I am using following addon to cycle through my Party frames : local f = CreateFrame("Button","TabParty",nil,"SecureActionButtonTemplate") f:SetAttribute("type","target") SecureHandlerWrapScript(f,"OnClick",f,[[ local unit for i=1,5 do TabPartyIndex = (TabPartyIndex or 0)%5+1 if TabPartyIndex==5 then unit = "player" else unit = "party"..TabPartyIndex end if UnitExists(unit) then self:SetAttribute("unit",unit) break end end ]]) Heres my Question: Is there a Way to alter the Code so the addon cycles in the Different direction? Id be super happy if someone could help me :D :banana: Greeting Furyan |
Need Help with Addon Code!
Hello everyone!
I am using following addon to cycle through my Party frames : local f = CreateFrame("Button","TabParty",nil,"SecureActionButtonTemplate") f:SetAttribute("type","target") SecureHandlerWrapScript(f,"OnClick",f,[[ local unit for i=1,5 do TabPartyIndex = (TabPartyIndex or 0)%5+1 if TabPartyIndex==5 then unit = "player" else unit = "party"..TabPartyIndex end if UnitExists(unit) then self:SetAttribute("unit",unit) break end end ]]) Heres my Question: Is there a Way to alter the Code so the addon cycles in the Different direction? Id be super happy if someone could help me Greeting Furyan |
I've not tried it but in theory you could change the for loop so that it goes from 5 to 1 in steps of -1.
for i = 5,1, -1 do ... end View the lua programming language for the 'for loop' to see what variety is available. Here is a link to the lua faq from wowwiki site. http://lua-users.org/wiki/LuaFaq |
Thanks for the Reply!
Unfortunately my Programming skill are about as good as my Mandarin (i dont speak Mandarin) hahahah I tried to swap 1,5 with 5,1 tho, but it didnt work :banana: Greetings Furyan |
Ahhh and another thing i forgot to mention:
With the addon active i can now use the Macro /click TabParty wich Values would i need to change so i can use /click TabParty2 for the opposite direction. ? Greetings |
Quote:
for i = 5,1,-1 do |
Thanks Kanegasi, looks like it is working with the -1 :D
|
But now i have to find a way to be able to use both addons at the same time, since i cannot use /click TabParty in two different ways and macros, if you understand what i mean (sorry for my bad english) :banana:
I tried adding a 2 after each "TabParty" in the Code, but thats not working . |
I think i made it!
local f = CreateFrame("Button","TabParty2",nil,"SecureActionButtonTemplate") f:SetAttribute("type","target") SecureHandlerWrapScript(f,"OnClick",f,[[ local unit for i=5,1,-1 do TabPartyIndex = (TabPartyIndex or 0)%5+1 if TabPartyIndex==5 then unit = "player" else unit = "party"..TabPartyIndex end if UnitExists(unit) then self:SetAttribute("unit",unit) break end end ]]) |
I am going to test it in a few Arena games and tell you if its working like i want it to :)
Thnaks for the Help! |
Ok the TabParty2 macro cycles in the same direction as the normal , no modified one... Hmmmm
|
The script you provided has the for loop using i but uses TabPartyIndex within the loop. Perhaps TabPartyIndex needs to be set to i ? For it to go in reverse order.
Can you provide the macro text that is working correctly. Maybe we can see why that is working and not the reverse. I suspect the reason above but best to compare code. |
Lua Code:
i=5,1,-1 or i=1,5,1 doesn't matter in this case. The real counting is: Lua Code:
|
Then that is the reason it doesn't reverse.
The for loop change I suggested was based on the for loop variable i being the new TabPartyIndex value. Dependant on how TabPartyIndex value is initialised may be what affects the result of that calculation inside the for loop. I would suggest displaying that TabPartyIndex value alongside i each time it is set and see how it changes each cycle of the for loop. If it results in the same value that i is inside the for loop then simply having TabPartyIndex set to i will correct your problem. Then changing the for loop i value as I suggested should result in the expected value. i = 1 > TabPartyIndex = i > party..TabPartyIndex > party1 i = 2 > TabPartyIndex = i > party..TabPartyIndex > party2 i = 3 > TabPartyIndex = i > party..TabPartyIndex > party3 i = 4 > TabPartyIndex = i > party..TabPartyIndex > party4 i = 5 > TabPartyIndex = i > party..TabPartyIndex > party5 > player i = 5 > TabPartyIndex = i > party..TabPartyIndex > party5 > player i = 4 > TabPartyIndex = i > party..TabPartyIndex > party4 i = 3 > TabPartyIndex = i > party..TabPartyIndex > party3 i = 2 > TabPartyIndex = i > party..TabPartyIndex > party2 i = 1 > TabPartyIndex = i > party..TabPartyIndex > party1 However, I always thought the player was party1, but I could be mistaken. |
If you just replace TabPartyIndex with i you would always target the same player.
For the increasing loop: i is always 1, 2, 3, 4 and then 5. We always want the next possible partymember as a target. Example: We used this button a few times and now TabPartyIndex is 3. First iteration: i=1, TabPartyIndex=4, if Party4 exists we stop Second iteration: i=2, TabPartyIndex=5, Player exists always so we stop If we use the button again it is time for the modulo trick First iteration: i=1, TabPartyIndex = 5%5 + 1 = 0+1 = 1, if Party1 exists we stop else we continue with TabPartyIndex=2 etc. With this method we can use both buttons to cycle back and forth through the group. |
Quote:
Once you determine you are in a party and use GNGM() + 1, use UnitIsUnit(unit, "player") to return the actual unit. |
To answer the OP's question about cycling in reverse:
Lua Code:
|
All times are GMT -6. The time now is 03:37 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI