Jockie Posted September 18, 2010 Share Posted September 18, 2010 I have this realy small problem, but I can't fix it.. Always says Base out of range. tonumber(string.gsub("$900","$", "")) and also tonumber(string.gsub("$900","$", ""),2) Both returns with nil. Link to comment
dzek (varez) Posted September 18, 2010 Share Posted September 18, 2010 http://www.lua.org/manual/5.1/manual.html It says all. $ is special character, and you have to escape it with % tonumber(string.gsub("$900","%$", "")) Link to comment
50p Posted September 20, 2010 Share Posted September 20, 2010 http://www.lua.org/manual/5.1/manual.html#pdf-tonumber You don't want to change the base parameter but string.gsub returns 2 values. One being the substring and the other the place (integer) at which the sub string starts. Both of these values are passed to your tonumber and it causes the error. Why? Because your base will be 1 (where $ is found), but you can't pass a value smaller than 2 and larger than 35. If you expect $ to be anywhere else than at start then you want to assign the first returned value from string.gsub to a variable and pass it to tonumber later but if you expect the $ to be as the first character then you can use this method instead: tonumber( string.sub( "$900", 2, -1 ) ) 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