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

stops on its own

Started by JackPS9, 18 June 2013 - 03:26 PM
JackPS9 #1
Posted 18 June 2013 - 05:26 PM
How can I get this to stop
It is stopping with the message "Too long without yielding"

local mon = peripheral.wrap("top")
p = peripheral.wrap("bottom")


while true do
  PR = p.getEnergyReceive()
  PS = p.getEnergySend()
  PL = p.getPowerProvider()


  mon.clear()
  mon.setCursorPos(1,1)
  mon.write("Receives: "..PR)


  cY = 2
  mon.setCursorPos(1,cY)
  mon.write("Sends:	"..PS)


  cY = 3
  mon.setCursorPos(1,cY)
  mon.write("Energy:   "..PL.energyStored)
end
MudkipTheEpic #2
Posted 18 June 2013 - 05:28 PM
Right before the last end, put a sleep(0.5) or any other reasonable time. To exit a loop, use the keyword: break .

Example of break :


--#Prints cake 10 times
x=1
while true do
if x>10 then
break
end
print("cake")
x=x+1
end
JackPS9 #3
Posted 18 June 2013 - 05:31 PM
alright gonna have to keep that sleep time in mind while using loops from now on.
As for stopping it, I dont want it to stop so :P/>
jakemg #4
Posted 18 June 2013 - 07:15 PM
you can just add sleep(0) every where there is a loop wether it be a while loop or for i=1,…. loop
MudkipTheEpic #5
Posted 18 June 2013 - 08:27 PM
you can just add sleep(0) every where there is a loop wether it be a while loop or for i=1,…. loop

That may be bad practice.

You don't need to go through a loop every 0.05 seconds to see if a condition has changed most of the time.
apemanzilla #6
Posted 19 June 2013 - 06:10 PM
You would want to add a short sleep delay as said above, but I wouldn't reccommend anything shorter than .1 seconds because that could cause an annoying flickering on the screen from rewriting so quickly, or, if your IRL computer isn't the best, could lag other computers a good amount.