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

Stuck In Some Loop I Think

Started by Copilot, 21 July 2013 - 05:43 PM
Copilot #1
Posted 21 July 2013 - 07:43 PM
http://pastebin.com/rAHs12nD

There's the pastebin link to the code. You should be able to see what the code does and how it works, I filled it to the brim with comments. Anyway, my problem is that whenever it executes the function to empty the turtle into a chest, it just stops as soon as the function executes, when an item appears in the 16th slot of the turtle. As soon as that happens, it just freezes, das it. No error message or anything, so I would imagine that it's looping indefinitely, but I could be wrong. Anyone have any idea what's happening?
Copilot #2
Posted 22 July 2013 - 04:20 PM
I don't understand what you're asking, but make your own post for it
Sharidan #3
Posted 22 July 2013 - 06:52 PM
Hmm … would need some extensive variable debugging …

One thing to note is your use of for loops. You specify an iteration step on pretty much all of them ??

Example:

for locationY = returnY, 1, 0 do
end

I wouldnt add a step of zero. That is probably the reason for the freeze you experience. You should only specify the step if you actually need to step up in intervals other than 1 or when stepping down…


-- This will dump 10 lines, one between each
for i = 1, 10 do
  print("line "..i)
end

-- This will step up by 2 each time
for i = 1, 10, 2 do
  print("line "..i)
end

-- This will go from 10 to 1
for i = 10, 1, -1 do
  print("line "..i)
end

You have specified the step as zero in a number of your for-loops. Try removing that zero so your up-counting for-loops only have 2 iteration instructions: from, to

This is the structure of the for-loop

for iterationVariable = from, to [optional: ,step] do
end

When counting down, you will need to add "step" to the for instruction.
Copilot #4
Posted 22 July 2013 - 07:51 PM
Alright, I'll try that and see how it goes