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

tonumber() not working

Started by Copilot, 22 June 2013 - 07:52 PM
Copilot #1
Posted 22 June 2013 - 09:52 PM
Pretty simple. I'm putting in tonumber(x), the program goes through, then when I come to the main while loop of my program, which is locationX < x, it says something along the lines of "attempt to compare number to string; got string", something like that. For reference, locationX was a variable that I initially declared as a number and x is a variable that was entered by the user and is supposed to be converted to a string from a number.
Lyqyd #2
Posted 23 June 2013 - 08:50 PM
Split into new topic.

Please post your whole code and the full text of any error messages you are receiving.
MysticT #3
Posted 24 June 2013 - 12:20 PM
Are you using

x = tonumber(x)
or just

tonumber(x)

The tonumber function will return the value converted to a number (or nil if it can't be converted). So, you have to store that return value somewhere.
Copilot #4
Posted 24 June 2013 - 11:03 PM
Aaaaaaaaaaaahh. Thank you very much, Malzahar