5 posts
Posted 01 January 2013 - 04:27 PM
Alright, I've written a script to the best of my newbie knowledge and I simply can't figure out why it's not digging out a room like it's supposed to. I'm not worried about torch placing, gravel detection, or any other fancy things. I am only trying to figure out why it will not dig a room of the specified size. I THINK my math.
Here's the script:
http://pastebin.com/8hQi2sZqI'm PRETTY SURE my math is correct where I use all those math.abs() commands. They're supposed to turn it so that it's facing the exact opposite direction of where it started facing. I'm using a miscperipherals compass mining turtle to do the job.
Thanks in advance!
818 posts
Posted 02 January 2013 - 01:37 PM
Try indenting some to make the code more readable.
2005 posts
Posted 02 January 2013 - 03:09 PM
IIRC, the compass returns a number from 0-3, corresponding to the facing that would be returned by the F3 debug info if you were looking in the same direction as the turtle.
If that's the case, then both facings will always be positive anyway, and all applying absolute value to their difference means is that you can't tell which was greater.
If you want to turn the turtle to face in the opposite direction, you just turnLeft twice. Boom, you're now facing the opposite direction.
2088 posts
Location
South Africa
Posted 02 January 2013 - 08:10 PM
So many people do this…
Instead of using input[1] [2] [3], store them into variables, especially if you're just begun. I still do it and I've been messing around with CC sometime now.
Also, your problem is because you don't
tonumber(input[1])
and the other inputs, right now they are strings.
818 posts
Posted 02 January 2013 - 10:05 PM
mje, for looops can run on strings. the only problem I see is you're using i as iteration variable on all loops. Try changing it so every for loop has it's own variable.
2088 posts
Location
South Africa
Posted 02 January 2013 - 10:09 PM
mje, for looops can run on strings. the only problem I see is you're using i as iteration variable on all loops. Try changing it so every for loop has it's own variable.
A lot of people fix there turtle programs by tonumbering the strings before using them in a loop. Although, when you do, it attempts to convert them into numbers but it is always good practice to convert them into numbers.
818 posts
Posted 02 January 2013 - 10:11 PM
Indeed it is, it is very good practice, through it is not the problem here. So hard to spot bugs though when you can't read the code because of bad indention
818 posts
Posted 02 January 2013 - 10:15 PM
Ehrm, the first for loop is "refacing" every time it runs. That should be a problem. you see, all code under the first for loop to the end of the program belongs to that for loop, since that's where your its 'end' is, though it is hidden by really bad indention
2005 posts
Posted 03 January 2013 - 02:57 AM
No, it's the z loop, the number of width layers to dig. Obviously it's supposed to contain everything else to the end.
The problem is that when the y dimension (height) is even the turtle ends up facing the opposite direction of how it started after digging out most of one plane of the room. So for reasons I can't really follow, Yobi want's to turn it about again in that situation, before digging the last row out.
This means that when the y dimension is odd, the turtle doesn't turn around before digging out the last row, so it hares off in the opposite direction.
And then, regardless of odd or even, the turtle tries to dig the next xy plane out at ninety degrees to the last one. I'm sure this is amusing to watch, but it doesn't end up digging a very good room.
5 posts
Posted 03 January 2013 - 06:41 AM
Sorry about the bad indentation and thanks for all the advice and help! I think I'll just rewrite the damn thing from scratch to fix the bad indentation and hopefully think of a good way to make it work.