Thread Tools Display Modes
10-01-08, 08:44 PM   #1
aetas
A Kobold Labourer
Join Date: Oct 2008
Posts: 1
editbox

ok, i am perty new to lua and i am having troubles geting numbers off the editbox to use for other functions. any help with this would be great.
  Reply With Quote
10-09-08, 10:49 AM   #2
Recompense
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 15
Originally Posted by aetas View Post
ok, i am perty new to lua and i am having troubles geting numbers off the editbox to use for other functions. any help with this would be great.
editbox:GetText() returns the text that's typed into the editbox. You could save this to a variable when the Enter key or a "save" button is pressed (what I usually do), or just leave the text the editbox, hide the editbox, and when you need the text, call GetText() on the box.
  Reply With Quote
10-09-08, 12:17 PM   #3
Maul
Ion Engines, Engage!
 
Maul's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 401
I set the OnTextChanged script handler for the editbox -

Code:
<OnTextChanged>
          someVar = tonumber(self:GetText()) or 0
</OnTextChanged>
That's basically what I do
__________________

Twitter: @IonMaul | Windows Live: [email protected] | Google Talk: [email protected]
  Reply With Quote
10-09-08, 01:04 PM   #4
Recompense
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 15
Originally Posted by Maul View Post
I set the OnTextChanged script handler for the editbox -

Code:
<OnTextChanged>
          someVar = tonumber(self:GetText()) or 0
</OnTextChanged>
That's basically what I do
A naive performance issue question - what's the drag on speed if you're saving the variable every single time the box has a text edit? I know that it's tiny, but I'm trying to learn more about which methods of saving / accessing data are the fastest for best practices.
  Reply With Quote
10-09-08, 03:31 PM   #5
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
Originally Posted by Recompense View Post
what's the drag on speed if you're saving the variable every single time the box has a text edit?
It's not noticeable.
  Reply With Quote
10-10-08, 10:10 AM   #6
Maul
Ion Engines, Engage!
 
Maul's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 401
Originally Posted by Recompense View Post
A naive performance issue question - what's the drag on speed if you're saving the variable every single time the box has a text edit? I know that it's tiny, but I'm trying to learn more about which methods of saving / accessing data are the fastest for best practices.
When considering performance, I divide it into two mind sets.

1) Addon Configuration - Don't worry too much about CPU usage, just don't make excessive garbage.

2) Addon Normal Usage - code for best possible performance.

But, yeah, setting the var with the script handler is not really going to affect anything. Now, if you were doing some very complex script calls (lots of table creation, sorting, what have you, then yeah, using OnTextChanged would not be ideal.

Bascially, you don't want to code yourself out of an easy solution just because you get OCD on CPU usuage. You have to keep in mind what the user is doing at the time the frame is being used or the function is being called. If it is used in a limited scope, then use the easy solution, which to me, is the snippet I posted above

If the editbox was being used in combat, then I might opt for the <OnEnteredPressed> script handler. I like <OnTextChanged> just because it will grab the entered data no matter how the user leaves the edit box (enter, escape, tab, alt-f4, whatever)

But for the OP's purposes, performance should not be an issue using that script handler.
__________________

Twitter: @IonMaul | Windows Live: [email protected] | Google Talk: [email protected]
  Reply With Quote
11-10-08, 06:06 PM   #7
thenaz
A Murloc Raider
Join Date: Nov 2008
Posts: 4
Little Help

Alot of this Lua is easy to figure out specially when I been programming in VB for years and dabbed in a few other languages as well. But I am still learning Lua. I can not figure out how to use variables very well yet. Maybe its just so basic that im over looking it. I am using a Frame with a few edit boxes on it and can not figure out how to call them in my functions in the lua file. Could use a little help here, Thanks a lot in advance.

NVM I figured it out.

function WspSnd_Click()
SendChatMessage(TextBox2:GetText(), "WHISPER", nil, TextBox1:GetText());
TextBox2:SetText("");
end

Last edited by thenaz : 11-11-08 at 02:18 AM. Reason: figured it out on my own
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » editbox


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