WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Need help for Addon please (https://www.wowinterface.com/forums/showthread.php?t=56799)

Furyan 10-24-18 06:40 AM

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

Furyan 10-24-18 07:16 AM

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

Xrystal 10-24-18 09:49 AM

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

Furyan 10-25-18 04:06 AM

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

Furyan 10-25-18 04:08 AM

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

Kanegasi 10-25-18 04:11 AM

Quote:

Originally Posted by Furyan (Post 330586)
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

You missed the negative one Xrystal mentioned.

for i = 5,1,-1 do

Furyan 10-25-18 04:22 AM

Thanks Kanegasi, looks like it is working with the -1 :D

Furyan 10-25-18 04:24 AM

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 .

Furyan 10-25-18 04:28 AM

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
]])

Furyan 10-25-18 04:29 AM

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!

Furyan 10-25-18 04:34 AM

Ok the TabParty2 macro cycles in the same direction as the normal , no modified one... Hmmmm

Xrystal 10-25-18 08:04 AM

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.

Urtgard 10-25-18 10:23 PM

Lua Code:
  1. local f = CreateFrame("Button","TabParty2",nil,"SecureActionButtonTemplate")
  2. f:SetAttribute("type","target")
  3. SecureHandlerWrapScript(f,"OnClick",f,[[
  4.     local unit
  5.     for i=1,5,1 do
  6.         TabPartyIndex = ((TabPartyIndex or 1) - 2)%5 + 1
  7.         if TabPartyIndex == 5 then
  8.             unit = "player"
  9.         else
  10.             unit = "party"..TabPartyIndex
  11.         end
  12.         if UnitExists(unit) then
  13.             self:SetAttribute("unit",unit)
  14.             break
  15.         end
  16.     end
  17. ]])

i=5,1,-1 or i=1,5,1 doesn't matter in this case.

The real counting is:
Lua Code:
  1. TabPartyIndex = (TabPartyIndex or 0)%5 + 1

Xrystal 10-26-18 02:42 AM

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.

Urtgard 10-26-18 05:31 AM

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.

myrroddin 10-26-18 12:38 PM

Quote:

Originally Posted by Xrystal (Post 330613)
However, I always thought the player was party1, but I could be mistaken.

AFAIK, player is never in partyN, but player will be in raidN. partyN is 1-4. If you are trying to find out how many total units are in your party, including the player, use GetNumGroupMembers() + 1, or just GetNumGroupMembers() by itself if you are in a raid.

Once you determine you are in a party and use GNGM() + 1, use UnitIsUnit(unit, "player") to return the actual unit.

myrroddin 10-26-18 12:55 PM

To answer the OP's question about cycling in reverse:
Lua Code:
  1. -- cycle all the units in the party, including the player, in reverse order
  2. local function ReverseParty()
  3.     for i = GetNumGroupMembers() + 1, -1 do
  4.         local unit = party..i
  5.         -- if unit is nil, it should be the player, but check anyway
  6.         if unit then
  7.             -- found party member
  8.             print("Found party member number party" .. party..i)
  9.         else
  10.             -- it is not partyN
  11.             print("Found the player")
  12.         end
  13.     end
  14. end


All times are GMT -6. The time now is 03:37 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI