lotrointerface.com
Search Downloads


Go Back   LoTROInterface > LotRO > Developer Discussions > Lua Programming Help (L)

Reply
Thread Tools Display Modes
  #1  
Unread 07-06-2011, 02:35 PM
Fortunis's Avatar
Fortunis Fortunis is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Mar 2011
Location: Leeds, UK
Posts: 72
ListBox number/string error (Help!) [SOLVED]

Heres the scenerio. Im making a Listbox for user input. The input range is 0-9999 and everything works according to plan with this until the next step.
Im placing an if-then-else-end statement in to check that no other characters/letters are used, for the listbox to be wiped clean and a message to the user that they inputted illegal data, but im getting 'attempt to compare number with nil' error.

Is there anything i can do to either allow the lua to ignore the error and carryon with the if-then-else-end statement or allow it to not do an error at all?

heres the code i have at the moment-

Code:
     ImageAmountInput:SetWantsKeyEvents( true );
     
     ImageAmountInput.KeyDown = function( sender, args )
        
        if args.Action == 162 then
            OpWindow:Activate();
            ImageAmountInput:SetSelection( 1, 4 );
            IAI = ImageAmountInput:GetText();
            IAI = tonumber( IAI );

            if  IAI >= 0 and IAI <= 9999 then -- ERROR produced here if non-numerical characters are used in user input box.
                ImageAmountInput:SetSelection( 0, 0 );
            else
                ImageAmountInput:SetText( "" );
                print ( "You entered an illegal entry" );
            end

        end

     end
__________________
Author of Mouse Cursor Highlighter Advanced

Last edited by Fortunis : 07-06-2011 at 03:14 PM.
Reply With Quote
  #2  
Unread 07-06-2011, 02:40 PM
MrJackdaw's Avatar
MrJackdaw MrJackdaw is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Feb 2009
Location: Lancaster, England
Posts: 249
You could always use a function to strip out the non-numeric characters and then check if it equals that which was entered.

Lua string tutorial at; http://lua-users.org/wiki/StringLibraryTutorial
__________________
************************************************** ************************************************** **
"Our ideals may never be realised, But they indicate what we are trying to do." Dick Tahta
Reply With Quote
  #3  
Unread 07-06-2011, 02:47 PM
Fortunis's Avatar
Fortunis Fortunis is offline
The Undying
Interface Author - Click to view interfaces
 
Join Date: Mar 2011
Location: Leeds, UK
Posts: 72
Hehe, ive just added an if-then-end before it to check if its not tonumber( IAI )

I guess the small break from staring at code gave me a little brain boost.

p.s. thanks for your fast response btw MrJackdaw



edit-


Code:
ImageAmountInput:SetWantsKeyEvents( true );
    ImageAmountInput.KeyDown = function( sender, args )
        
        if args.Action == 162 then
            OpWindow:Activate();
            ImageAmountInput:SetSelection(1, 4);
            IAI = ImageAmountInput:GetText();
            IAI = tonumber( IAI );
            if not tonumber( IAI ) then -- <--- Fixes everything
                ImageAmountInput:SetText( "" );
                print ( "You entered an illegal entry" );
            elseif  IAI >= 0 and IAI <= 9999 then -- ERROR produced here if string characters used in user input box. Need to figure out a way to ignore erroring.
                ImageAmountInput:SetSelection(0,0);
            end
        end
    end
__________________
Author of Mouse Cursor Highlighter Advanced

Last edited by Fortunis : 07-06-2011 at 02:52 PM.
Reply With Quote
Reply


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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox MrJackdaw Lua Programming Help (L) 3 05-31-2011 04:06 AM
LotRO annoyance number one. Digital_Utopia General Authoring Discussion (L) 3 01-12-2011 09:22 AM
Number Cooldown on Hotbar instead of timer? therams Interface Requests (L) 3 12-19-2010 05:56 AM
SVN error The Old One Site help, bugs, suggestions/questions 5 09-28-2010 03:46 PM
XML Version Number Question Kaylan XML modification help (L) 2 04-02-2007 11:34 AM


All times are GMT -5. The time now is 09:15 AM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui