Thread Tools Display Modes
11-15-21, 11:26 AM   #1
Khanod
A Defias Bandit
Join Date: Nov 2021
Posts: 3
Connecting action to button

I am new to this so I am missing something likely very simple. I need to click a button which then runs through a for loop and each time the for loop executes an blizzard api. I have 7 buttons and they show up so long as I place the SetScript below all the buttons. on button press it should send the tab number to the for loop and then go through the loop until complete. It does not do anything when I press the button now.


UIConfig.GT6toBagButton = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate");
UIConfig.GT6toBagButton:SetPoint("CENTER", UIConfig, "TOP", 0, -190);
UIConfig.GT6toBagButton:SetSize(140, 40);
UIConfig.GT6toBagButton:SetText("GT6 to Bag");
UIConfig.GT6toBagButton:SetNormalFontObject("GameFontNormalLarge");
UIConfig.GT6toBagButton:SetHighlightFontObject("GameFontHighlightLarge");


UIConfig.GT7toBagButton = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate");
UIConfig.GT7toBagButton:SetPoint("CENTER", UIConfig, "TOP", 0, -220);
UIConfig.GT7toBagButton:SetSize(140, 40);
UIConfig.GT7toBagButton:SetText("GT7 to Bag");
UIConfig.GT7toBagButton:SetNormalFontObject("GameFontNormalLarge");
UIConfig.GT7toBagButton:SetHighlightFontObject("GameFontHighlightLarge");


UIConfig.GT1toBagButton:SetScript("OnClick", fromGT(self, event, 1));
UIConfig.GT2toBagButton:SetScript("OnClick", fromGT(self, event, 2));
UIConfig.GT3toBagButton:SetScript("OnClick", fromGT(self, event, 3));
UIConfig.GT4toBagButton:SetScript("OnClick", fromGT(self, event, 4));
UIConfig.GT5toBagButton:SetScript("OnClick", fromGT(self, event, 5));
UIConfig.GT6toBagButton:SetScript("OnClick", fromGT(self, event, 6));
UIConfig.GT7toBagButton:SetScript("OnClick", fromGT(self, event, 7));

local function fromGT(self, event, tabNumber)
local tab = tabNumber;

for slot = 1, 98, 1 do
AutoStoreGuildBankItem(tabNumber,slot);
end
end
  Reply With Quote
11-15-21, 11:55 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Code that runs before anything declared as local can't "see" it.

Move your fromGT function declaration to before you start creating the buttons (or at least before the SetScripts(xxx) section)

You should be getting errors so I would also suggest intalling BugSack and Bugrabber to help detecting them.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 11-15-21 at 11:58 AM.
  Reply With Quote
11-15-21, 12:07 PM   #3
Khanod
A Defias Bandit
Join Date: Nov 2021
Posts: 3
still no action

I simplified the lua to below, no action happens onclick. This tab is completely full so there is an item in tab1 slot 1.


local UIConfig = CreateFrame("Frame", "NinjaMover_Frame", UIParent, "BasicFrameTemplateWithInset");

UIConfig:SetSize(150, 300);
UIConfig:SetPoint("RIGHT", UIParent, "RIGHT");

UIConfig.title = UIConfig:CreateFontString(nil, "OVERLAY");
UIConfig.title:SetFontObject("GameFontHighlight");
UIConfig.title:SetPoint("LEFT", UIConfig.TitleBg, "LEFT", 5, 0);
UIConfig.title:SetText("Ninja Mover");

-- Buttons

UIConfig.GT1toBagButton = CreateFrame("Button", nil, UIConfig, "GameMenuButtonTemplate");
UIConfig.GT1toBagButton:SetPoint("CENTER", UIConfig, "TOP", 0, -40);
UIConfig.GT1toBagButton:SetSize(140, 40);
UIConfig.GT1toBagButton:SetText("GT1 to Bag");
UIConfig.GT1toBagButton:SetNormalFontObject("GameFontNormalLarge");
UIConfig.GT1toBagButton:SetHighlightFontObject("GameFontHighlightLarge");


local function fromGT(self, event)
AutoStoreGuildBankItem(1,1);
end

UIConfig.GT1toBagButton:SetScript("OnClick", fromGT(self, event));
  Reply With Quote
11-15-21, 12:13 PM   #4
Khanod
A Defias Bandit
Join Date: Nov 2021
Posts: 3
Also, I tried putting a print("Hello"); inside the function fromGT(). The "Hello" shows up at reload which means the function is getting executed at startup and not when it is called from the OnClick.
  Reply With Quote
11-15-21, 12:17 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
Lua Code:
  1. local function fromGT(self)
  2.     print("Button Clicked!")
  3.     AutoStoreGuildBankItem(1,1);
  4. end
  5.  
  6. UIConfig.GT1toBagButton:SetScript("OnClick", fromGT);

Adding the brackets to fromGT() in the SetScript means you a calling the function then as part of the SetScript rather than telling the SetScript to USE the function when the OnClick script is run.

Added a print so you can see if the function has been called.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Connecting action to button

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