dudeks Posted October 10, 2011 Share Posted October 10, 2011 Hi. I need a function isNumeric() to check an writed to gui text. Anywho have this function? :> Link to comment
LoveFist Posted October 10, 2011 Share Posted October 10, 2011 function isNumeric(text) return tonumber(text) end Link to comment
karlis Posted October 10, 2011 Share Posted October 10, 2011 function isNumeric(text) return tonumber(text) end correction function isNumeric(text) return tonumber(text) and true or false end Link to comment
dudeks Posted October 10, 2011 Author Share Posted October 10, 2011 If text is: "18a" > \main_s.lua:174: attempt to compare number with nil It's don't work. I test it some times ago. Link to comment
arezu Posted October 10, 2011 Share Posted October 10, 2011 function isNumeric(value) if(value == tonumber(value))then return true else return false end Link to comment
dudeks Posted October 10, 2011 Author Share Posted October 10, 2011 This same. main_s.lua:174: attempt to compare number with nil Link to comment
arezu Posted October 10, 2011 Share Posted October 10, 2011 show how you are calling the function in your script Link to comment
karlis Posted October 10, 2011 Share Posted October 10, 2011 function isNumeric(text) if type(text)~="string" and type(text)~="number" then return false end return tonumber(text) and true or false end Link to comment
dudeks Posted October 10, 2011 Author Share Posted October 10, 2011 age = guiGetText(editage) if isNumeric(age) then .... end edit: function isNumeric(text) if type(text)~="string" and type(text)~="number" then return false end return tonumber(text) and true or false end is working. Thanks! Link to comment
AGENT_STEELMEAT Posted October 11, 2011 Share Posted October 11, 2011 Weird, I had: function isNumeric(text) if type(text) ~= "string" then text = tostring(text) end return tonumber(text) and true or false end Link to comment
karlis Posted October 11, 2011 Share Posted October 11, 2011 function isNumeric(text) if type(text) == "string" then text = tostring(text) end return text and true or false end 2mistakes. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now