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

Need help finding a bug

Started by Master_Jynx, 12 March 2014 - 04:12 PM
Master_Jynx #1
Posted 12 March 2014 - 05:12 PM
The script is at http://pastebin.com/EbhD0vUV
I making a mining script that mines 3 layers at a time
Each time it finnishes a group of layers, it should move to the corner of the quarry below the start position,
where it saves those coordinates, before climbing to the start position to unload and refuel.

It works correctly for the 1st group of layers, returns as expected, then moves down to the saved coordinates
to begin digging at a new level.
When it finnishes the 2nd group of levels, it does return to the correct corner, but when it should climb up
to the start position, it instead of moves 1 block up and 1 block down in an endless loop.
ctrl+t and ctrl+r will not stop it, the turtle has to be broken before it crashes the game.

Iv'e pasteda modified sample of the problem section at http://pastebin.com/QzBR0Nad
Line 14 appear to be the problem, it alternates between tru and false no matter what the value of CurrentY is
twormtwo #2
Posted 13 March 2014 - 12:04 AM
On line 335 of the first pastebin, you have:

a = (CurrentY < Y1) and moveUp() or moveDown()
Here is the same code with parenthesis to show what is executed first:

a = ((CurrentY < Y1) and (moveUp() or moveDown()))
It basically is telling the computer to move up then down (as "or" executes both statements, and takes the boolean values returned and sees if either are true).
A better way of doing that is:

if CurrentY < Y1 then
  moveUp()
else
  moveDown()
end

I also want to thank you for actually reading and following the directions on how to ask a proper question on the Ask a Pro, most don't. If you need any more help/explanation, just ask!
CometWolf #3
Posted 13 March 2014 - 05:34 AM
It basically is telling the computer to move up then down (as "or" executes both statements, and takes the boolean values returned and sees if either are true).

This is incorrect. Provided the first statement does not return nil or false, the second or statement will never execute. Same thing goes for and, but in reverse. If the first statement returns nil or false, the second is never executed.