WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Connecting action to button (https://www.wowinterface.com/forums/showthread.php?t=58978)

Khanod 11-15-21 11:26 AM

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

Fizzlemizz 11-15-21 11:55 AM

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.

Khanod 11-15-21 12:07 PM

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

Khanod 11-15-21 12:13 PM

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.

Fizzlemizz 11-15-21 12:17 PM

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.


All times are GMT -6. The time now is 10:33 PM.

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