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

Help me my program have a error

Started by Perdigero96, 01 August 2016 - 01:02 PM
Perdigero96 #1
Posted 01 August 2016 - 03:02 PM
Hi
My Name is Perdigero96.

I programmed a program for the doorbell of a house; the idea was that when the bell call at an advanced screen out a message saying someone had called with two options to allow or deny entry; the thing is that soon after turning on the computer gives me an error saying "Peripheral:40: Too long without yielding"

Someone can check the code and tell me what is the fail?



This is the code:
  • while true do
  • mon = peripheral.find("monitor")
  • mon.clear()
  • x=redstone.getInput("back")
  • if x == true then
  • mon.setCursorPos(12,6)
  • mon.write("Someone had called")
  • mon.setCursorPos(20,9)
  • mon.write("¿Can entry?")
  • mon.setCursorPos(15,15)
  • mon.write("YES")
  • mon.setCursorPos(35,15)
  • mon.write("NO")
  • event, side, xPos, yPos = os.pullEvent("monitor_touch")
  • print(xPos)
  • print(yPos)
  • if xPos == 16 and yPos == 15 then
  • rednet.open("bottom")
  • rednet.broadcast("granted")
  • rednet.broadcast("puerta")
  • rednet.close()
  • elseif xPos == 35 and yPos == 15 then
  • rednet.open("bottom")
  • rednet.broadcast("denied")
  • rednet.close()
  • end
  • end
  • end
Lupus590 #2
Posted 01 August 2016 - 08:16 PM
[./code] tags

move your second line out of your loop (just above will be fine)

also, you can open rednet and happily leave it open, no need to close it all the time
Edited on 01 August 2016 - 06:16 PM
TheRockettek #3
Posted 01 August 2016 - 09:16 PM
make it yield as if it cant find a redstone input at the back it will just repeat the loop wthout yielding at all. Doing sleep() will make it yield
Lyqyd #4
Posted 02 August 2016 - 12:48 AM
Or better yet, os.pullEvent("redstone") will have it wait until the redstone state changes.