Quantcast
WoWInterface - View Single Post - Adding new script to pet journal buttons
View Single Post
06-10-21, 09:54 PM   #1
Walkerbo
A Flamescale Wyrmkin
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 135
Adding new script to pet journal buttons

Hi all

I am trying to add a new script to the pet journal buttons.

I can do it manually for each button using this chunk;
Lua Code:
  1. PetJournalListScrollFrameButton1:SetScript(
  2.     "OnClick",
  3.     function()
  4.         print("PetJournalListScrollFrameButton1")
  5.     end
  6. )
  7. PetJournalListScrollFrameButton2:SetScript(
  8.     "OnClick",
  9.     function()
  10.         print("PetJournalListScrollFrameButton2")
  11.     end
  12. )
  13. PetJournalListScrollFrameButton3:SetScript(
  14.     "OnClick",
  15.     function()
  16.         print("PetJournalListScrollFrameButton3")
  17.     end
  18. )
  19. PetJournalListScrollFrameButton4:SetScript(
  20.     "OnClick",
  21.     function()
  22.         print("PetJournalListScrollFrameButton4")
  23.     end
  24. )
  25. -- etc

However, if I try to build a loop to add the script to each button it doesn't work;
Lua Code:
  1. for index = 1, 11 do
  2.     buttonName = ("PetJournalListScrollFrameButton" .. index)
  3.     print(buttonName) -- debug --
  4.     _G[buttonName]:SetScript(
  5.         "OnClick",
  6.         function()
  7.             print(buttonName) -- debug --
  8.         end
  9.     )
  10. end

This is the result I am seeing;


My questions are;
Why does manually setting the script work but not the loop?
How do I get the loop to correctly add the script to each pet button?
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote