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

Detect if input is number or name

Started by tfoote, 06 July 2012 - 09:31 PM
tfoote #1
Posted 06 July 2012 - 11:31 PM
Can you detect if an input such as

x =  io.read()
is a number or a word
MysticT #2
Posted 06 July 2012 - 11:33 PM
You can detect if it's a number or not like this:

local input = read() -- get the input, doesn't really matter how
if tonumber(input) ~= nil then
  -- the input is a number
else
  -- the input is a word
end