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

Odd Program End

Started by sunspark, 10 August 2013 - 08:35 AM
sunspark #1
Posted 10 August 2013 - 10:35 AM
Title: Odd Program End

So, I'm facing a weird program stop that is making no sense to me what so ever. The program:


debug = true
m = peripheral.wrap("right");
craftSources = {
  {
	ID = 1,
	craftTargets = {98, 10425}
  },
  {
	ID = 4,
	craftTargets = {1, 10425}
  },
  {
    ID = 331,
    craftTargets = {10458}
  },
  {
    ID = 10458,
    craftTargets = {256, 266}
  }
}
while 0 ~= 1 do
  for i, craftSource in pairs(craftSources) do
	for j, craftTarget in pairs(craftSource["craftTargets"]) do
      items = m.listItems()
	  if (items[craftSource["ID"]] ~= nil and (items[craftTarget] == nil or items[craftSource["ID"]] > items[craftTarget])) then
		if debug then print("Crafting "..craftTarget) end
        pcall(m.craft, craftTarget, 1)
		sleep(1)
	  end
	end
  end
end

I'm using MiscPeripherials to try and get my AE system to precraft some of the items that take time to craft (such as smooth stone and the like), while still keeping some of the source material (such as cobblestone).

It works, correctly identifying what needs to be crafted, but after a random number of iterations, the program stops, with no error message. Since I have what should be an infinite loop on the outside, I'm a bit confused as to why it's stopping.

I am still running Minecraft 1.52, and CC 1.53, as some of the mods that I use have not yet updated to 1.6.

Any thoughts would be appreciated.
Edited on 10 August 2013 - 08:39 AM
Bubba #2
Posted 10 August 2013 - 10:44 AM
Split into new topic.
Termanater13 #3
Posted 10 August 2013 - 12:06 PM
the while loop you have "while 0 ~= 1 do" try "while true do". also it looks like there is a missing end in the code in that same while loop. the formatting looks odd with the tabs being used so I may have just missed it.

edit
I found an extra end not a missing end. also try changing the for loop variables. you have the for pairs loop using a pre existing variable.
Bubba #4
Posted 10 August 2013 - 12:17 PM
the while loop you have "while 0 ~= 1 do" try "while true do".
No, that is perfectly fine. The statement 0 ~= 1 will always evaluate to true, so it is in effect the exact same thing as "while true do".

I found an extra end not a missing end. also try changing the for loop variables. you have the for pairs loop using a pre existing variable.

Nowhere in the program does he have an extra end or use the same variable twice. Please read more carefully.

@OP - Are you leaving the turtle to go do other things? If so, are you leaving the chunk? That would stop the program if that were the case.
Termanater13 #5
Posted 10 August 2013 - 12:19 PM
the while loop you have "while 0 ~= 1 do" try "while true do".
No, that is perfectly fine. The statement 0 ~= 1 will always evaluate to true, so it is in effect the exact same thing as "while true do".

I found an extra end not a missing end. also try changing the for loop variables. you have the for pairs loop using a pre existing variable.

Nowhere in the program does he have an extra end or use the same variable twice. Please read more carefully.

@OP - Are you leaving the turtle to go do other things? If so, are you leaving the chunk? That would stop the program if that were the case.
then could it be the debug script he has the rest looks fine
edit or the pcall()

edit edit
it may just be running nonstop so it may just end on its own. if there is no wait involved I have seen computercraft computer programs just end.
Bubba #6
Posted 10 August 2013 - 12:24 PM
edit or the pcall()

pcall is "protected call". It is a way to call functions so that the program will not end if there is an error, and though I don't know if it's necessary here it certainly should not be the root of the problem.
Termanater13 #7
Posted 10 August 2013 - 12:25 PM
edit or the pcall()

pcall is "protected call". It is a way to call functions so that the program will not end if there is an error, and though I don't know if it's necessary here it certainly should not be the root of the problem.
I edited my last post with what if there is no sleep/wait in the code
Bubba #8
Posted 10 August 2013 - 12:41 PM
I edited my last post with what if there is no sleep/wait in the code

That's not the problem either. The OP said no errors were being thrown, and the issue you're talking about throws a "too long without yeild" error. Not to mention the fact that he has a sleep(1) in his code.
Termanater13 #9
Posted 10 August 2013 - 01:13 PM
The only thing left is to double check the if statement after the "items = m.listItems()" and make sure no other functions is forcing the while loop to break.

edit
try running the code without pcall. pcall catchng the error thus not being shown on screen, but returning it.

edit edit
I ran the code in FTB unleashed 1.1.3 and cant find any issues. as far as the Item IDs I have no Idea what some of them are. but testing with stone, and stone bricks it just runs non stop crafting every loop for the while loop. I did however had to remove the rest the rest of the IDs since it crashed my client. other then the ID edit it was the same code and I now have no Idea what could be causing the issue.

edit edit edit
once the stone got to the same amount as the bricks I got the "bios:150: Too long without Yielding" which cant be what you are having issues with since you do not have errors.
Edited on 10 August 2013 - 01:31 PM
sunspark #10
Posted 11 August 2013 - 12:40 AM
The only thing left is to double check the if statement after the "items = m.listItems()" and make sure no other functions is forcing the while loop to break.

edit
try running the code without pcall. pcall catchng the error thus not being shown on screen, but returning it.

edit edit
I ran the code in FTB unleashed 1.1.3 and cant find any issues. as far as the Item IDs I have no Idea what some of them are. but testing with stone, and stone bricks it just runs non stop crafting every loop for the while loop. I did however had to remove the rest the rest of the IDs since it crashed my client. other then the ID edit it was the same code and I now have no Idea what could be causing the issue.

edit edit edit
once the stone got to the same amount as the bricks I got the "bios:150: Too long without Yielding" which cant be what you are having issues with since you do not have errors.

No - I wasn't getting any error at all. The program just stops. I'm not using a mod pack, and my item ID's are assigned by hand, so it's not surprising that the mod items don't match up with a FTB instance.

The code was originally while true do, but that was one of the things I changed while trying to resolve this. I also added the pcall around the craft, as I though misc peripherals might be throwing some kind of silent error that was not being logged even though it was halting the program.

It never got far enough along to run into the error you found - it was stopping while I still had about 20k more smooth stone then bricks, but it's something that I need to take care of - a flag to check if something has been crafted, and a sleep after the for loop should take care of that problem. Guess I'm going to have to fall back on the old print statements after each line to see where exactly the program is halting on me. Thanks for taking a look.