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:
PetJournalListScrollFrameButton1:SetScript(
"OnClick",
function()
print("PetJournalListScrollFrameButton1")
end
)
PetJournalListScrollFrameButton2:SetScript(
"OnClick",
function()
print("PetJournalListScrollFrameButton2")
end
)
PetJournalListScrollFrameButton3:SetScript(
"OnClick",
function()
print("PetJournalListScrollFrameButton3")
end
)
PetJournalListScrollFrameButton4:SetScript(
"OnClick",
function()
print("PetJournalListScrollFrameButton4")
end
)
-- etc
However, if I try to build a loop to add the script to each button it doesn't work;
Lua Code:
for index = 1, 11 do
buttonName = ("PetJournalListScrollFrameButton" .. index)
print(buttonName) -- debug --
_G[buttonName]:SetScript(
"OnClick",
function()
print(buttonName) -- debug --
end
)
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?