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

[Lua] Too long without yielding

Started by petterroea, 30 April 2012 - 06:11 PM
petterroea #1
Posted 30 April 2012 - 08: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?
cant_delete_account #2
Posted 30 April 2012 - 08:16 PM

while not redstone.getInput("back") do
os.queueEvent("randomEvent")
os.pullEvent()
i = 1
end
Fixed code. ^^
petterroea #3
Posted 30 April 2012 - 08:18 PM
Thanks!

Also, how do i read a file, and get the string in a variable named "password")
petterroea #4
Posted 30 April 2012 - 08:24 PM
Sorry, the code just hangs the pc. Any other way of waiting for input of redstone?
MysticT #5
Posted 30 April 2012 - 08: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.
cant_delete_account #6
Posted 30 April 2012 - 08:34 PM
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
ComputerCraftFan11 #7
Posted 01 May 2012 - 06:39 PM
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 on 01 May 2012 - 04:39 PM
GewoonDaan #8
Posted 03 September 2012 - 12:03 PM
What if you want your turtle/computer to do a certain thing until it receives a redstone pulse?
Skillexs #9
Posted 15 May 2013 - 07: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