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

Attempt to compare number with string expected, got number

Started by SpawnDeck, 24 May 2013 - 08:15 PM
SpawnDeck #1
Posted 24 May 2013 - 10:15 PM
Hello, I've been doing ComputerCraft for a little while and just coding in general. I'm really baffled by what's happening with my code here, so I looked up my error message and didn't find a good answer. My code is as follows:


function redstoneEmit(side)
  redstone.setOutput(side, true)
  sleep(1)
  redstone.setOutput(side, false)
  sleep(1)
end
args = {...}
x = args[1]
y = args[2]
  if x < 0 then
	x = -x
	for i=1,x do
	  redstoneEmit("left")
	end
  else
	for i=1,x do
	  redstoneEmit("front")
	end
  end
  if y < 0 then
	y = -y
	for i=1,y do
	  redstoneEmit("back")
	end
  else
	for i=1,y do
	  redstoneEmit("right")
	end
  end

I know my code's a bit sloppy, I had to mess with it a bunch trying to solve my problem. It tells me that my error is on line 12, which is where I try to compare my first command line argument to 0. My code here is designed to move a Redpower frame, exported redstone signals to different sides of the computer to signal frame motors. I want to keep the command line arguments limited to two, just your forwards and sideways motions. A negative number is designed to indicate moving backwards or right, while positive is designed to move forward or left. If you're interested, the pastebin for the code is at http://pastebin.com/U0n6q5wS. Thanks for your help!
Edited by
Lyqyd #2
Posted 25 May 2013 - 12:27 AM
Split into new topic.

Use `x = tonumber(args[1])`, etc.
SpawnDeck #3
Posted 26 May 2013 - 02:22 PM
It works perfectly! Thanks!