Im attempting my first proper computercraft program, I want to map the height of X blocks (3 for now, it will be a set area later) with respect to where the turtle started at. so at every moment the turtle should know its Y position relative to its starting point. ie whenever the turtle goes down, the currect location will be -1, if it goes up, then 1.
it will work by making the turtle go up to a certain Y point and then dropping it until it reaches the floor, recording the value of Y, and going up again and moving forward, then repeat.
after that, the y position will be stored in a matrix (its 3x3 for now because im planning to make it scan a 3x3 area soon.) and be printed at the end of the program with colours.
I can retrieve and print the colours of the matrix fine, but for the love of god the turtle just breaking my head. it keep going up one block every time it goes forward, and I cant figure out why. any help is appriciated.
pastebin : http://pastebin.com/pQUrw0Nq
things to note :
maxY is the maximum y distance the turtle will go away from the origin y point. (not ready yet )
cy is the current y potision of the turtle.
Im really not sure whats going on there, and Im brekaing my head over this for over 3 hours now, whats basically is happening is that if the turtle is placed above a block, it will detect it, then go up an extra block from its origin, and go down to detect the next block, and then repeat that, which will give me a false +1 y block value every time...
*Im not sure if its fit to be in ask a pro, but hey, why not give it a shot?
code:
ypos = {} maxY = 3 cy = 0 function doStuff(xx) for ymax = 1, maxY do if turtle.detectDown() then ypos[xx] = {cy, cy, cy} for cy = cy, 0 do turtle.up() cy = cy +1 if cy == 0 then turtle.forward() cy = cy -1 end end else turtle.down() cy = cy -1 end end end function getColour(int) if int <= -5 then return colors.blue end if int == -4 then return colors.purple end if int == -3 then return colors.magenta end if int == -2 then return colors.cyan end if int == -1 then return colors.lightBlue end if int == 0 then return colors.pink end if int == 1 then return colors.yellow end if int == 2 then return colors.lime end if int == 3 then return colors.green end if int == 4 then return colors.brown end if int >= 5 then return colors.red end return colors.green end term.clear() term.setCursorPos(0,0) for xx = 1, 3 do doStuff(xx) end for xx = 1, 3 do for zz = 1, 3 do term.setBackgroundColor(getColour(ypos[xx][zz])) term.setCursorPos(xx,zz) print (" ") end end