Jump to content




tonumber() not working


  • You cannot reply to this topic
3 replies to this topic

#1 Copilot

  • Members
  • 7 posts

Posted 22 June 2013 - 08: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.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 23 June 2013 - 07:50 PM

Split into new topic.

Please post your whole code and the full text of any error messages you are receiving.

#3 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 24 June 2013 - 11:20 AM

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.

#4 Copilot

  • Members
  • 7 posts

Posted 24 June 2013 - 10:03 PM

Aaaaaaaaaaaahh. Thank you very much, Malzahar





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users