generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: "Attempted to compare number to a string"

Previous Thread :: Next Thread 
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
14 Jul 2014 09:11 AM
my code(not ROBLOX Lua):
~~
io.write("Enter a number from 1 to 10: ")
input = io.read()

OG = 7

if input > 10 then
print("Please enter a number less than 10 next time!")
elseif input < 1 then
print("Please enter a number greater than 1 next time!")
elseif input == OG then
print("Our guess was: " .. OG .. ", you also entered: " .. input .. "!")
else
print("Our guess was: " .. OG)
end
~~

i just do not know. :/
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
14 Jul 2014 09:12 AM
I'm assuming it's the user's input that is creating the error, but I don't know.
Report Abuse
marioblox1094 is not online. marioblox1094
Joined: 14 Aug 2010
Total Posts: 1839
14 Jul 2014 09:16 AM
You need to convert the input from a string to a number.
Report Abuse
Zecrit is not online. Zecrit
Joined: 24 Jan 2013
Total Posts: 2618
14 Jul 2014 09:17 AM
Can you post what line the error is on because I have a suspicion as to what is wrong.
Report Abuse
marioblox1094 is not online. marioblox1094
Joined: 14 Aug 2010
Total Posts: 1839
14 Jul 2014 09:18 AM
The input automatically thinks it's a string, so you need to convert it to an integer
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
14 Jul 2014 09:22 AM
Well, I'm using an IDE. The IDE didn't show an error.
Report Abuse
marioblox1094 is not online. marioblox1094
Joined: 14 Aug 2010
Total Posts: 1839
14 Jul 2014 09:24 AM
What language is this if I may ask?
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
14 Jul 2014 09:24 AM
?

This is Lua.
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
14 Jul 2014 09:24 AM
I found the fix anyways. I just converted the user input to a number. :/

~~~~~~~
io.write("Enter a number from 1 to 10: ")
input1 = io.read()

input = tonumber(input1)

OG = 7

if input > 10 then
print("Please enter a number less than 10 next time!")
elseif input < 1 then
print("Please enter a number greater than 1 next time!")
elseif input == OG then
print("Our guess was: " .. OG .. ", you also entered: " .. input .. "!")
else
print("Our guess was: " .. OG)
end
~~~~~~~
Report Abuse
marioblox1094 is not online. marioblox1094
Joined: 14 Aug 2010
Total Posts: 1839
14 Jul 2014 09:27 AM
Oh. It's not like I told you twice to do that anyways.
Report Abuse
blox6137 is not online. blox6137
Joined: 23 Nov 2008
Total Posts: 1109
14 Jul 2014 09:28 AM
OH, I'M SORRY THAT I DIDN'T KNOW HOW TO CONVERT A NUMBER TO A STRING.
Smart ass. Why do you think I was asking for help?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image