←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft


Problem with table ?

Fiixii52's Photo Fiixii52 25 Jun 2016


I'm trying to write my own first big turtle program. It consists of a quarry program, with modulable dimensions and enderchests to take fuel and send ores.
I wrote a table (Called MiningSave) where the turtle can determine if it has reached the limit of the zone it has to dig.
In other words, when having dug a full line, the turtle is supposed to turn and change the line to continue digging.
I used arguments to type variables into the program (With Arguments = {...})

The problem is that after many testing, the turtle won't stop digging forward instead or restricting himself in the zone.

Here is a pastebin link to the program : http://pastebin.com/nYGg1eCV

I tried many things to localise the problem's source, and I think it occurs in line 272 and further. But I have absolutely no idea what it can be because, to my eyes, I don't see any errors (Correct me if I'm wrong though, I'm what you could call a Lua newbie lol).

Any help please ?


KingofGamesYami's Photo KingofGamesYami 25 Jun 2016

First thing I noticed that was weird is these lines:
                           MiningSave[1] = MiningSave[2]
                           MiningSave[2] = (Perimeter-2*MiningSave[1])/2 -- Calculates the new width with the perimeter which stays the same. If we would have typed MiningSave[2] = MiningSave[1], it would have taken the new value of MiningSave[1].

While this might work, I would do this:
                           local temp = MiningSave[ 1 ]
                           MiningSave[1] = MiningSave[2]
                           MiningSave[2] = temp

MKlegoman357's Photo MKlegoman357 25 Jun 2016

Common, this is Lua:

MiningSave[1], MiningSave[2] = MiningSave[2], MiningSave[1]