r/ComputerCraft • u/MinceraftIsSus • Jan 17 '26
My program is erroring because a ROM program is running too long without yielding
I'm not sure what I'm supposed to do to fix this...
22
Upvotes
r/ComputerCraft • u/MinceraftIsSus • Jan 17 '26
I'm not sure what I'm supposed to do to fix this...
5
u/9551-eletronics Computercraft graphics research Jan 17 '26
this doesnt actually mean the rom is running too long
if you run the program multiple times it will cause different errors
the issue here is that your program is running too long and probably running some functions that are in rom, when the yielding timeout happens it just throw the error wherever the execution currently is. this is very likely an issue with your code not yielding and here it just so happened to trigger when your code was running something that has its source in rom
i cant say what is causing this but i assume it will be the internal while loop you have but i cant really say since that condition is abysmal and relaly hard to read, also the formatting is very confusing. it might be yielding, it might not, heck now looking at it further it could be that the inner while never runs (cause the pullEvent seems to be under it?? hard to say with the bad indentation)
which would mean that it never runs pullEvent and never yields. idk why this is written like this but its probably you not understand how this code is actually flowing because of bad formatting which leads to there not being any yield in the main loop, why not put the event getter at the start of the main loop and reformat it properly
3
u/Bright-Historian-216 Jan 17 '26
i often put sleep(0.05) inside a loop when nothing there yields just for good measure
1
u/pytness Jan 17 '26
you might need to create a coroutine and use coroutine.yield()
i dont remember if that exist on cc, but it does on lua.
edit: nevermind, i believe using a sleep(0.01) should work
1
u/BurningCole Jan 17 '26 edited Jan 17 '26
I don't think the os.pullEvent is guarenteed to run each loop, only when target is greater than current. You probably want to replace the "else if" with "elseif" anr remove one of the "end"s.
EDIT: I don't think it can even get into the relay loop as it requires relay to not be nil, but you set relay to nil immediately before. You should probably set it as while relay == nil or ...
1
u/Brokedownbad Jan 17 '26
it means that the program is running without sleeps. Just put a sleep(0) in there somewhere.
1
u/Insurgentbullier NIH patient Jan 18 '26
Okay, I've converted the image to text and formatted it, because it was really hard to read. Hopefully I didn't make any errors.
Anyways, I think the problem lies in the fact that you're only yielding in the 'else' clause. And somehow
if target > current thenstays true for a very long time. So move pull the pullEvent out of theelseclause so it always gets triggered.But then I recommend not using
os.startTimer(1), because pausing for 1 whole second seems kinda long. idk 🤷Reformatted code for anyone else on mobile that wants to weigh in: