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

How do I read an inputted variable as an integer?

Started by d_wootang, 30 January 2013 - 07:49 AM
d_wootang #1
Posted 30 January 2013 - 08:49 AM
io.read() seems to always output to the variable as text, and I need it as an integer to sanitize and interpret the input for use in my functions. I've never used Lua prior to last night, so any help would be appreciated.
The code in question(I commented out the parts in question so I could test other functions)

shell.run('clear')
print("How long do you want the quarry to be?")
length = io.read()
–if length>64 or length<8 then
– print("Please input a number between 8 and 64:")
– length = io.read()
–end

print("How wide do you want the quarry to be?")
width = io.read()
–if width>64 or width<8 then
– print("Please input a number between 8 and 64:")
– width = io.read()
–end
Doyle3694 #2
Posted 30 January 2013 - 08:58 AM
lenght = tonumber(read())
d_wootang #3
Posted 30 January 2013 - 09:18 AM
That worked, thanks