hi everyone
I have started writing a program for a turtle and had a problem
with the text that I wrote in and if then.
I mad a test program of it.
Pastebin: dFUegsb7
If I typed in 1 the out was:
1
wrong
oke
I have no idea whtat i did wrong could anyone please help?
4 replies to this topic
#1
Posted 27 March 2015 - 07:23 PM
#2
Posted 27 March 2015 - 08:04 PM
The function 'read' returns a string, not a number. You can use the function 'tonumber' to convert a string to a number:
local input = tonumber( read() )
if input then --# if the user entered a number
print("You entered the number: ", input)
else
print("You didn't enter a valid number")
end
#3
Posted 27 March 2015 - 08:13 PM
whoo thanks a lot 
But does if then not work with strings?
But does if then not work with strings?
#4
Posted 28 March 2015 - 12:07 AM
tonumber() returns nil if it can't convert its parameter to a numeral, so tonumber(read()) will indeed return nil if anything but a number is typed.
#5
Posted 30 March 2015 - 03:45 PM
Thanks again 
And here is the finalized code: http://www.computerc...545#entry211545
and pastbin: http://pastebin.com/AfFDnjki
And here is the finalized code: http://www.computerc...545#entry211545
and pastbin: http://pastebin.com/AfFDnjki
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











