Hero192 Posted August 27, 2015 Posted August 27, 2015 Hey guys, i want to be sure of these lua functions , tonumber and tostring don't recomand me the lua.org website because it's hard to get it from them. Give me some examples only if you are sure you know about these functions i wont get something wrong Thanks
GTX Posted August 27, 2015 Posted August 27, 2015 tonumber and tostring are pretty self-explanatory. tonumber converts i.e strings to number and tostring converts to string.
Hero192 Posted August 27, 2015 Author Posted August 27, 2015 For example: i have a table i will get something from the table and convert them and tell me if im wrong or right local Table= { {"Jack",900}, } for index, v in ipairs (Table) do outputChatBox(tostring(v[1]).. " got " ..tonumber(v[2]).."$",root,255,0,0) end
ixjf Posted August 27, 2015 Posted August 27, 2015 Clearly wrong. The values in the table are already of the type you're converting to. You use these functions when you have, for example, a variable of type number, and want to convert it to a string type, or vice versa.
anumaz Posted August 27, 2015 Posted August 27, 2015 You'd use tonumber() if you have a string that you want to convert to a number: 900 == tonumber("900") -- or local variable = "1275" -- If here you do: variable + 50 -- it will return an error because 'variable' is a string. You'd need to do: tonumber(variable) + 50 It's the same otherwise. "900" ~= 900 It'd need to be "900" == tostring(900) Hope that helps...
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