Jump to content




Too long without wielding CC 1.7

computer peripheral help

3 replies to this topic

#1 graywolf69

  • Members
  • 44 posts

Posted 15 June 2015 - 02:09 AM

I'm getting a too long without yielding error, no idea how to fix it (I do know that I'm not doing it right, but haven't done CC in a while). Here's the program, I know I'm supposed to pastebin but it is too short to bother.

cap = peripheral.wrap("back")

mon = peripheral.wrap("top")

maxE = cap.getMaxEnergyStored("west")

curE = cap.getEnergyStored("west")

mon.clear()
mon.setCursorPos(1,1)
while true do
mon.write(curE.."/"..maxE)
end

Thanks!

Edited by graywolf69, 15 June 2015 - 02:13 AM.


#2 apemanzilla

  • Members
  • 1,421 posts

Posted 15 June 2015 - 02:14 AM

Simple answer: Add this in the while loop, after writing to the monitor:
sleep(1)
Additionally, you never update the curE and maxE variables. Try this code:
cap = peripheral.wrap("back")
mon = peripheral.wrap("top")
mon.clear()
mon.setCursorPos(1,1)
while true do
  mon.write(cap.getEnergyStored("west").."/"..cap.getMaxEnergyStored("west"))
  sleep(1)
end 
Complicated answer: "Yielding" allows CC to run other computers as well as yours. If you run a program without yielding in some form (sleeping, pulling an event, etc) the program will crash because it can't run other computers if one is hogging the thread.

Edited by apemanzilla, 15 June 2015 - 02:16 AM.


#3 graywolf69

  • Members
  • 44 posts

Posted 15 June 2015 - 03:34 AM

So basically, this will make it update every second instead of constantly, which isn't allowed? Great! Thanks!

#4 DarkEyeDragon

  • Members
  • 31 posts
  • LocationBelgium

Posted 15 June 2015 - 11:52 AM

View Postgraywolf69, on 15 June 2015 - 03:34 AM, said:

So basically, this will make it update every second instead of constantly, which isn't allowed? Great! Thanks!
Basicly. also if you want to refresh it asap you could use sleep(0.1) in this case it would still refresh very quickly. Altough i don't recommend to use it if you don't need it. It could start slowing down your server/computer quite fast if you have enough of those scripts running heavy tasks.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users