This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
reiman2222's profile picture

read()

Started by reiman2222, 19 June 2012 - 01:01 AM
reiman2222 #1
Posted 19 June 2012 - 03:01 AM
how can i get read() to take in a number instead of a string.
BigSHinyToys #2
Posted 19 June 2012 - 03:07 AM
No but you can convert a string to a number with tonumber()


local variable = tonumber(read())
reiman2222 #3
Posted 19 June 2012 - 03:09 AM
well all i want to do is take the string 4 an make it the number 4
BigSHinyToys #4
Posted 19 June 2012 - 03:13 AM
the tonumber() function takes a string and converts it to number.
reiman2222 #5
Posted 19 June 2012 - 03:18 AM
im trying to make a program that takes a number i type ex:4 and evaluates as the number 4 and evaluates it as 4 and not ist string value
BigSHinyToys #6
Posted 19 June 2012 - 03:30 AM
there is no function capable of reading a value into a program in a number format. there is how ever a way to change a string into a number this is with the tonumber() function. this function takes a string and converts it into a number. this number can now be used as you would any other number in lua. this line will read in a string then convert it to a number and dump that NUMBER into the variable "variable"

local variable = tonumber(read())
see this for more info
reiman2222 #7
Posted 19 June 2012 - 03:40 AM
ok i understand now thank you