Jump to content




[Lua] Too long without yielding


8 replies to this topic

#1 petterroea

  • New Members
  • 5 posts

Posted 30 April 2012 - 07:11 PM

Basically, i need my program to wait for redstone input. But it crashes, with the error: "Too long without yielding".

This is how i wait:

while redstone.getOutput("back") == false do
i = 1
end

How can i stop my program from crashing?

#2 cant_delete_account

  • Members
  • 484 posts

Posted 30 April 2012 - 07:16 PM

while not redstone.getInput("back") do
os.queueEvent("randomEvent")
os.pullEvent()
i = 1
end
Fixed code. ^^

#3 petterroea

  • New Members
  • 5 posts

Posted 30 April 2012 - 07:18 PM

Thanks!

Also, how do i read a file, and get the string in a variable named "password")

#4 petterroea

  • New Members
  • 5 posts

Posted 30 April 2012 - 07:24 PM

Sorry, the code just hangs the pc. Any other way of waiting for input of redstone?

#5 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 30 April 2012 - 07:34 PM

Queueing too many events is probably the problem. This is what the "redstone" event is for:
while true do
  os.pullEvent("redstone")
  if rs.getInput("back") then
    break
  end
end
It will wait for any change in redstone input and then check if the input is in the side you want and break the loop if it is.

#6 cant_delete_account

  • Members
  • 484 posts

Posted 30 April 2012 - 07:34 PM

View Postpetterroea, on 30 April 2012 - 07:24 PM, said:

Sorry, the code just hangs the pc. Any other way of waiting for input of redstone?
Try this:
while true do
sleep(0)
local event = os.pullEvent()
if event == "redstone" then
  break
end
end


#7 ComputerCraftFan11

  • Members
  • 771 posts
  • LocationHawaii

Posted 01 May 2012 - 05:39 PM

View Postpetterroea, on 30 April 2012 - 07:18 PM, said:

Thanks!

Also, how do i read a file, and get the string in a variable named "password")

file = fs.open("filenname", "r") -- r = read only
correctPass = file:read()
file:close()
Then you can do
write("Password: ")
if read("*") == correctPass then
   --your code
end

(Oops, didn't see your other post)

Edited by ComputerCraftFan11, 01 May 2012 - 05:39 PM.


#8 GewoonDaan

  • New Members
  • 9 posts

Posted 03 September 2012 - 11:03 AM

What if you want your turtle/computer to do a certain thing until it receives a redstone pulse?

#9 Skillexs

  • Members
  • 9 posts

Posted 15 May 2013 - 06:21 AM

I have the problem withe 3 codes working together
http://pastebin.com/B4ZpxpmV
http://pastebin.com/yQSvCCQK
http://pastebin.com/jypAecUh
and on the turtle it says
Too long without yielding
but on computer nothing





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users