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

Simple High low game not working

Started by PublicSaix, 13 March 2015 - 10:27 PM
PublicSaix #1
Posted 13 March 2015 - 11:27 PM
Heres the error bios:366: [string "guess"]:7: ambiguous syntax (function call x new statement)

heres the code

print("think of the number (1-100")
number = math.random(1,100)

while true do
number = io.read()

(if) number == tonumber(number) then

print("damn, youre a good guesser")
break

else

if tonumber(number) > number then
print("Too low")
else
print("Too High")
end


please help.
HPWebcamAble #2
Posted 14 March 2015 - 12:11 AM
First, put code in code blocks: [.code] [./code]
(With out the period)

Second, your error is a simple fix:

you put 'if' in parentheses (Which Lua thinks is some sort of function)
(On line 7)


Looking over your code, I think you'll run into an eof error after you fix this one


print("think of the number (1-100")
number = math.random(1,100)

while true do
  number = io.read()
  if number == tonumber(number) then
	print("damn, youre a good guesser")
	break
  elseif tonumber(number) > number then --#make else and if into one word, elseif
	print("Too low")
  else
	print("Too High")
  end
end --#After indenting, we see that you need another 'end' for the while statement

Code errors aside, this won't work as you intend. You set 'number' to a random number, then override it with the user input!
Edited on 13 March 2015 - 11:14 PM
PublicSaix #3
Posted 14 March 2015 - 12:36 AM
First, put code in code blocks: [.code] [./code]
(With out the period)

Second, your error is a simple fix:

you put 'if' in parentheses (Which Lua thinks is some sort of function)
(On line 7)


Looking over your code, I think you'll run into an eof error after you fix this one


print("think of the number (1-100")
number = math.random(1,100)

while true do
  number = io.read()
  if number == tonumber(number) then
	print("damn, youre a good guesser")
	break
  elseif tonumber(number) > number then --#make else and if into one word, elseif
	print("Too low")
  else
	print("Too High")
  end
end --#After indenting, we see that you need another 'end' for the while statement

Code errors aside, this won't work as you intend. You set 'number' to a random number, then override it with the user input!



https://www.youtube.com/watch?v=seuWeVZkETw skip to 23 minutes i had my setup exactly the same as his but it gave me this error bios 366 [string "guess"]:5: unexpected symbol
HPWebcamAble #4
Posted 14 March 2015 - 12:59 AM
https://www.youtube....h?v=seuWeVZkETw skip to 23 minutes i had my setup exactly the same as his but it gave me this error bios 366 [string "guess"]:5: unexpected symbol

If your code was the code you posted, then you didn't have it exact
Just realized his code is cut off, since the screen only shows so much.

You pretty much did have it exact, but you missed a few important 'end' s

Line 5 could have given you an unexpected symbol if you reversed 'io.read()' and 'guess'.

io.read() = guess --# This will error, since it is trying to set 'io.read()' to 'guess'

'guess = io.read()' by itself should be fine
PublicSaix #5
Posted 14 March 2015 - 04:56 AM
https://www.youtube....h?v=seuWeVZkETw skip to 23 minutes i had my setup exactly the same as his but it gave me this error bios 366 [string "guess"]:5: unexpected symbol

If your code was the code you posted, then you didn't have it exact
Just realized his code is cut off, since the screen only shows so much.

You pretty much did have it exact, but you missed a few important 'end' s

Line 5 could have given you an unexpected symbol if you reversed 'io.read()' and 'guess'.

io.read() = guess --# This will error, since it is trying to set 'io.read()' to 'guess'

'guess = io.read()' by itself should be fine



thanks i got it working
PublicSaix #6
Posted 14 March 2015 - 05:10 AM
https://www.youtube....h?v=seuWeVZkETw skip to 23 minutes i had my setup exactly the same as his but it gave me this error bios 366 [string "guess"]:5: unexpected symbol

If your code was the code you posted, then you didn't have it exact
Just realized his code is cut off, since the screen only shows so much.

You pretty much did have it exact, but you missed a few important 'end' s

Line 5 could have given you an unexpected symbol if you reversed 'io.read()' and 'guess'.

io.read() = guess --# This will error, since it is trying to set 'io.read()' to 'guess'

'guess = io.read()' by itself should be fine

its actually not working
there arent any errors its just that there is no right number
any tips?
Lyqyd #7
Posted 14 March 2015 - 05:26 AM
Please paste the current code.
HPWebcamAble #8
Posted 14 March 2015 - 05:30 AM
its actually not working
there arent any errors its just that there is no right number
any tips?

Make sure you use separate variables for the user input and the random number

If you are still stumped, like Lyqyd said, paste the current code.
PublicSaix #9
Posted 14 March 2015 - 05:40 AM
its actually not working
there arent any errors its just that there is no right number
any tips?

Make sure you use separate variables for the user input and the random number

If you are still stumped, like Lyqyd said, paste the current code.
i feel dumb but im still stumped


print("Guess that number (1-100)")
number = math.random(1,100)

while true do
guess = io.read()

if guess == tonumber(guess) then

print("damn youre a good guesser")
break

elseif tonumber(guess) > number then
print("Too High")
else
print("Too Low")
end
end
Bomb Bloke #10
Posted 14 March 2015 - 05:58 AM
guess == tonumber(guess)?
PublicSaix #11
Posted 14 March 2015 - 06:04 AM
guess == tonumber(guess)?


ive never written so im not sure what needs to be changed
Bomb Bloke #12
Posted 14 March 2015 - 06:13 AM
I'd suggest comparing number to a numeric version of guess instead.
PublicSaix #13
Posted 14 March 2015 - 06:21 AM
I'd suggest comparing number to a numeric version of guess instead.


i dont know what that means lol

im not a programmer i just started computercraft (learning le basics)
Bomb Bloke #14
Posted 14 March 2015 - 06:24 AM
Your seventh line reads like this:

if guess == tonumber(guess) then

You are comparing the string "guess" to a numeric representation of "guess". They will never be equal, because on one side you've got a string, and on the other you've got a number.

You want to compare your guess to your hidden number:

if number == tonumber(guess) then
PublicSaix #15
Posted 14 March 2015 - 06:31 AM
Your seventh line reads like this:

if guess == tonumber(guess) then

You are comparing the string "guess" to a numeric representation of "guess". They will never be equal, because on one side you've got a string, and on the other you've got a number.

You want to compare your guess to your hidden number:

if number == tonumber(guess) then
thanks all you guys rock!!