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

[Solved]What Is Bad In This Line?

Started by Lux, 01 September 2013 - 05:57 AM
Lux #1
Posted 01 September 2013 - 07:57 AM
Hi! I wrote a program for call an elevator but the main computer tell me 'startup:11: attempt to compare string with number expected, got string'. I checked the code and I didn't find what is wrong.

The code:

rednet.open("top")
mouseWidth = 0
mouseHeight = 0
monitor = peripheral.wrap("left")
monitor.clear()
monitor.setBackgroundColour((colours.red))
monitor.setCursorPos(1,3)
monitor.write[[ Llamar  ascensor ]]
monitor.setBackgroundColour((colors.black))
function elevatorCaller()
  if mouseWidth > 0 and mouseWidth < 9 and mouseHeight == 3 then
   for i=1,5 do
	rednet.send(2, "down")
	sleep(1.1)
   end
   for i=1,5 do
	rednet.send(3, "down")
	sleep(1.1)
   end
   rednet.send(4, "down")
  end
end
repeat
event,p1,p2,p3 = os.pullEvent()
if event == "monitor_touch" then
  mouseWidth = p1
  mouseHeight = p2
  elevatorCaller()
end
until event == "char" and p1 == ("x")

Thanks!
Kingdaro #2
Posted 01 September 2013 - 08:36 AM
In your event loop, you set mouseWidh to p1, which is returned as the side of the touched monitor, and not the x position. Use p2 and p3 for x and y.

Also, I would recommend sending the x and y to your elevatorCaller() as params in the event loop, and accepting them as mouseWidth and mouseHeight. It'll streamline your code a bit.
Lux #3
Posted 01 September 2013 - 10:14 AM
In your event loop, you set mouseWidh to p1, which is returned as the side of the touched monitor, and not the x position. Use p2 and p3 for x and y.

Also, I would recommend sending the x and y to your elevatorCaller() as params in the event loop, and accepting them as mouseWidth and mouseHeight. It'll streamline your code a bit.
:o/> I don't saw that I used p1 for mouseWidth and p2 for mouseHeight. Thanks for tell me, I was getting crazy hehe.