Jump to content




Too Long Without Yielding


3 replies to this topic

#1 Abstract

  • New Members
  • 7 posts

Posted 22 February 2012 - 03:13 PM

I need some help with my program. What it should do is,output redstone to the left, if redstone comes from the front, stop outputting redstone to the right wait and reboot. this is my code:
startup:
while true do
shell.run"redside"
end
redside:
redstone.setOutput("right", true)
if redstone.getInput("front", true)
then redstone.setOutput("right", false)
sleep(10)
os.restart()
end
but if I reboot now, it works for only a couple of seconds and a error pops up which says 'Too long without yielding'. What did I do wrong?

#2 luza

  • New Members
  • 43 posts
  • LocationGermany

Posted 22 February 2012 - 03:27 PM

you forgot some brackets.

while true do
shell.run("redside")
end


#3 Casper7526

    OG of CC

  • Members
  • 362 posts

Posted 22 February 2012 - 03:28 PM

When your code just loops endlessly without yielding for a few seconds, you receive that error.

You should use a pullevent to only check when redstone is changed instead.

startup:
redstone.setOutput("right", true)
while true do
event, param = os.pullEvent()
   if event == "redstone" and redstone.getInput("front") == true then
   redstone.setOutput("right", false)
   sleep(10)
   redstone.setOutput("right", true)
   end
end


#4 Abstract

  • New Members
  • 7 posts

Posted 22 February 2012 - 03:46 PM

 Casper7526, on 22 February 2012 - 03:28 PM, said:

When your code just loops endlessly without yielding for a few seconds, you receive that error.

You should use a pullevent to only check when redstone is changed instead.

startup:
redstone.setOutput("right", true)
while true do
event, param = os.pullEvent()
   if event == "redstone" and redstone.getInput("front") == true then
   redstone.setOutput("right", false)
   sleep(10)
   redstone.setOutput("right", true)
   end
end
[string "redside"]:4: 'then' expected
Don't know why I've typed everything like you
EDIT: works, had a spelling mistake <_</>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users