Quantcast Need help for Addon please - WoWInterface
Thread Tools Display Modes
10-24-18, 06:40 AM   #1
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
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

Greeting Furyan
  Reply With Quote
10-24-18, 07:16 AM   #2
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
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

Last edited by Furyan : 10-24-18 at 07:17 AM. Reason: Typo
  Reply With Quote
10-24-18, 09:49 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,256
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
__________________
  Reply With Quote
10-25-18, 04:06 AM   #4
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
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

Greetings Furyan
  Reply With Quote
10-25-18, 04:08 AM   #5
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
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
  Reply With Quote
10-25-18, 04:11 AM   #6
Kanegasi
A Frostmaul Preserver
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 295
Originally Posted by Furyan View Post
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

Greetings Furyan
You missed the negative one Xrystal mentioned.

for i = 5,1,-1 do
  Reply With Quote
10-25-18, 04:22 AM   #7
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
Thanks Kanegasi, looks like it is working with the -1
  Reply With Quote
10-25-18, 04:24 AM   #8
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
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)

I tried adding a 2 after each "TabParty" in the Code, but thats not working .

Last edited by Furyan : 10-25-18 at 04:26 AM. Reason: additional info
  Reply With Quote
10-25-18, 04:28 AM   #9
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
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
]])
  Reply With Quote
10-25-18, 04:29 AM   #10
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
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!
  Reply With Quote
10-25-18, 04:34 AM   #11
Furyan
A Murloc Raider
Join Date: Oct 2018
Posts: 9
Ok the TabParty2 macro cycles in the same direction as the normal , no modified one... Hmmmm
  Reply With Quote
10-25-18, 08:04 AM   #12
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,256
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.
__________________
  Reply With Quote
10-25-18, 10:23 PM   #13
Urtgard
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 4
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

Last edited by Urtgard : 10-25-18 at 10:36 PM.
  Reply With Quote
10-26-18, 02:42 AM   #14
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,256
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.
__________________
  Reply With Quote
10-26-18, 05:31 AM   #15
Urtgard
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 4
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.
  Reply With Quote
10-26-18, 12:38 PM   #16
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 957
Originally Posted by Xrystal View Post
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.
  Reply With Quote
10-26-18, 12:55 PM   #17
myrroddin
A Molten Giant
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 957
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

Last edited by myrroddin : 10-26-18 at 01:00 PM. Reason: better logic
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Need help for Addon please

Thread Tools
Display Modes

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