Thread Tools Display Modes
07-28-17, 09:45 AM   #1
Mortimerlol
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Jul 2017
Posts: 71
Editbox and Button sync...

Hello, somebody can say me the error? I need print the text typed in a editbox when press the respective button.
Lua Code:
  1. Gui.func3frame.input = CreateFrame("EditBox", "same", Gui.func3frame, 'InputBoxTemplate')
  2. Gui.func3frame.input:SetSize(200,22)
  3. Gui.func3frame.input:SetAutoFocus(false)
  4. Gui.func3frame.input:SetMaxLetters(30)
  5. Gui.func3frame.input:SetPoint("CENTER", -65, 30)
  6. Gui.func3frame.input:SetScript('OnEnterPressed', function(arg3)
  7.     local arg3 = self:GetText()
  8. end)
  9. --
  10. Gui.func3frame.add = CreateFrame("Button", "same", Gui.func3frame, "UIPanelButtonTemplate")
  11. Gui.func3frame.add:SetSize(50,22)
  12. Gui.func3frame.add:SetPoint("CENTER", 70, 30)
  13. Gui.func3frame.add:SetText("Add")
  14. Gui.func3frame.add:SetScript("OnClick", function(arg3)
  15.     print("added: " ..arg3)
  16. end)
Thanks, and sorry! Maybe I'm asking too much.
  Reply With Quote
07-28-17, 11:05 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
local means local to that chunk of code. In this case, only the editbox "OnEnterPressed" can see it.
Code:
Gui.func3frame.input = CreateFrame("EditBox", "same", Gui.func3frame, 'InputBoxTemplate')
    Gui.func3frame.input:SetSize(200,22)
    Gui.func3frame.input:SetAutoFocus(false)
    Gui.func3frame.input:SetMaxLetters(30)
    Gui.func3frame.input:SetPoint("CENTER", -65, 30)
    Gui.func3frame.input:SetScript('OnEnterPressed', function(self, arg3)
        self:GetParent().arg3 = self:GetText()
    end)
    --
    Gui.func3frame.add = CreateFrame("Button", "same", Gui.func3frame, "UIPanelButtonTemplate")
    Gui.func3frame.add:SetSize(50,22)
    Gui.func3frame.add:SetPoint("CENTER", 70, 30)
    Gui.func3frame.add:SetText("Add")
    Gui.func3frame.add:SetScript("OnClick", function(self, arg3)
        print("added: " ..self:GetParent().arg3)
        -- or print("added: " ..self:GetParent().input:GetText())
    end)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 07-28-17 at 11:09 AM.
  Reply With Quote
07-28-17, 12:15 PM   #3
Mortimerlol
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Jul 2017
Posts: 71
Originally Posted by Fizzlemizz View Post
local means local to that chunk of code. In this case, only the editbox "OnEnterPressed" can see it.
Code:
Gui.func3frame.input = CreateFrame("EditBox", "same", Gui.func3frame, 'InputBoxTemplate')
    Gui.func3frame.input:SetSize(200,22)
    Gui.func3frame.input:SetAutoFocus(false)
    Gui.func3frame.input:SetMaxLetters(30)
    Gui.func3frame.input:SetPoint("CENTER", -65, 30)
    Gui.func3frame.input:SetScript('OnEnterPressed', function(self, arg3)
        self:GetParent().arg3 = self:GetText()
    end)
    --
    Gui.func3frame.add = CreateFrame("Button", "same", Gui.func3frame, "UIPanelButtonTemplate")
    Gui.func3frame.add:SetSize(50,22)
    Gui.func3frame.add:SetPoint("CENTER", 70, 30)
    Gui.func3frame.add:SetText("Add")
    Gui.func3frame.add:SetScript("OnClick", function(self, arg3)
        print("added: " ..self:GetParent().arg3)
        -- or print("added: " ..self:GetParent().input:GetText())
    end)
Works fantastic now. Final code:
Lua Code:
  1. Gui.func3frame.input = CreateFrame("EditBox", "same", Gui.func3frame, 'InputBoxTemplate')
  2. Gui.func3frame.input:SetSize(200,22)
  3. Gui.func3frame.input:SetAutoFocus(false)
  4. Gui.func3frame.input:SetMaxLetters(30)
  5. Gui.func3frame.input:SetPoint("CENTER", -65, 30)
  6. Gui.func3frame.input:SetScript('OnChar', function(self, addenemy)
  7.     self:GetParent().addenemy = self:GetText()
  8. end)
  9. --
  10. Gui.func3frame.add = CreateFrame("Button", "same", Gui.func3frame, "UIPanelButtonTemplate")
  11. Gui.func3frame.add:SetSize(50,22)
  12. Gui.func3frame.add:SetPoint("CENTER", 70, 30)
  13. Gui.func3frame.add:SetText("Add")
  14. Gui.func3frame.add:SetScript("OnClick", function(self, addenemy)
  15.     print("|cff009900+ Added |r" ..self:GetParent().addenemy.." |cff009900to hate list.")
  16.     Gui.func3frame.input:SetText("")
  17.     -- print("added: " ..self:GetParent().input:GetText())
  18. end)
THANKS Fizzlemizz
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Editbox and Button sync...


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