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

Getting error, don't know why. Help?

Started by vandbg, 11 June 2012 - 08:20 PM
vandbg #1
Posted 11 June 2012 - 10:20 PM
From what I understand I should be looking for a typo, but I can't find it.

This is the error: bios:206: [string "RPS" ]:42: ')' expected

This is the code:

local playerscore=0
local computerscore=0
for Variable = 1, 3 do
local x=read()
local y=math.random(3)

if y==1
then print("Rock")
elseif y==2
then print("Paper")
elseif y==3
then print("Scissors")
end

if (x=="rock" and y==1) or
(x=="paper" and y==2) or
(x=="scissors" and y==3)
then sleep(1) print("Draw!")
elseif (x=="rock" and y==2) or
(x=="paper" and y==3) or
(x=="scissors" and y==1)
then sleep(1) print("Computer wins round!")
computerscore=computerscore+1
elseif (x=="rock" and y==3) or
(x=="paper" and y==1) or
x=="scissors" and y==2)
then sleep(1) print ("Player wins round!")
playerscore=playerscore+1
end

end

if (computerscore=playerscore)
then print("Draw!")

elseif (playerscore>computerscore)
then term.clear()
print("YOU WIN!")

elseif (playerscore<computerscore)
then print("YOU FAIL!")
end

_______________

Thanks a lot
MysticT #2
Posted 11 June 2012 - 10:30 PM
After formatting the code, It was easy to find the errors:

local playerscore=0
local computerscore=0
for Variable = 1, 3 do
  local x=read()
  local y=math.random(3)

  if y==1 then
	print("Rock")
  elseif y==2 then
	print("Paper")
  elseif y==3 then
	print("Scissors")
  end

  if (x=="rock" and y==1) or (x=="paper" and y==2) or (x=="scissors" and y==3) then
	sleep(1)
	print("Draw!")
  elseif (x=="rock" and y==2) or (x=="paper" and y==3) or (x=="scissors" and y==1) then
	sleep(1)
	print("Computer wins round!")
	computerscore=computerscore+1
  elseif (x=="rock" and y==3) or (x=="paper" and y==1) or x=="scissors" and y==2) then -- error 1: missing the ( in the third condition
	sleep(1)
	print ("Player wins round!")
	playerscore=playerscore+1
  end
end

if (computerscore=playerscore) then -- error 2: use == here to compare instead of =
  print("Draw!")
elseif (playerscore>computerscore) then
  term.clear()
  print("YOU WIN!")
elseif (playerscore<computerscore) then
  print("YOU FAIL!")
end
Ther might be some other errors, but not with the syntax.
vandbg #3
Posted 12 June 2012 - 09:57 PM
Ah, thanks. It was the single '=' messing it up.
Bossman201 #4
Posted 13 June 2012 - 04:29 AM
After formatting the code, It was easy to find the errors:
This is why I love reading your posts, Mystic.