7 posts
Posted 14 February 2013 - 08:24 AM
The script is supposed to be run like 'myscript 10 10 10' where the three arguments are the x,z, and y of the size of the room I want the turtle to dig.
When I run this script with or without any arguments it just outputs '8' to the screen and the turtle does nothing.
http://pastebin.com/WPZX2Rmu
8543 posts
Posted 14 February 2013 - 08:45 AM
Split into new topic.
818 posts
Posted 14 February 2013 - 08:51 AM
You aren't actually getting the arguments. The arguments should be taken from the ultimate outzoom of your program, so not in a block.
Neither are you using table indexes correctly, they should be incased in []'s, so something like
{["x"] = tonumber(args[1]), ["z"] = tonumber(args[2]), ["y"] = tonumber(args[3]) }
7 posts
Posted 14 February 2013 - 09:15 AM
You aren't actually getting the arguments. The arguments should be taken from the ultimate outzoom of your program, so not in a block.
This makes sense. I had suspected I wasn't getting the arguments but I was having trouble seeing if that was true.
Neither are you using table indexes correctly, they should be incased in []'s, so something like
{["x"] = tonumber(args[1]), ["z"] = tonumber(args[2]), ["y"] = tonumber(args[3]) }
Hrm, according to the lua-users wiki the two are the same.
http://lua-users.org/wiki/TablesTutorialI moved the args = {…} to the beginning of the script and changed the table to look like you say and I'm still getting the same results.
818 posts
Posted 14 February 2013 - 09:23 AM
Well it printing 8 is pretty much impossible. It lacks both prints and writes
7 posts
Posted 14 February 2013 - 09:25 AM
I agree, which is why I'm completely baffled by why this program is acting the way it is.
436 posts
Posted 14 February 2013 - 09:52 AM
Query: have you added debug prints to figure out if it runs, and how far? Nevermind, answered my own question by looking at the code.
I've had a program do something similar to this, and never did figure out why. I eventually sat down to systematically change certain variables to see if anything helped. I think I determined it was something to do with loops, but it fixed itself before I could ascertain what it was, and could NEVER reproduce it.
7 posts
Posted 14 February 2013 - 09:58 AM
I actually threw in some print statements at the beginning of each function to see where it is derping out.
Turns out none of my functions are running at all.
7 posts
Posted 14 February 2013 - 10:04 AM
As a side note, the turtle seems to be functioning properly. My tunnel script works perfectly.
What is really bending my brain is the '8'. I've gotten a couple of other numbers out of it once or twice when I picked it up and put it back down.
8543 posts
Posted 14 February 2013 - 10:22 AM
Neither are you using table indexes correctly, they should be incased in []'s, so something like
{["x"] = tonumber(args[1]), ["z"] = tonumber(args[2]), ["y"] = tonumber(args[3]) }
Actually, they were just fine. Obviously, it wouldn't have actually caught anything, but the declarations were perfectly valid.
OP, you can also use dimensions.x and dimensions.y, etc. instead of needing dimensions['x']. Lua allows that for indexing tables when using string literals as the key. The biggest problem is that your code could use some re-jiggering. Move the initial dimensions table declarations out of a function and just have them run at the beginning of the program. Get rid of the main() function, since it adds no value in Lua. Just run the code it contains after setting up the dimension table at the beginning and declaring your other functions.
7 posts
Posted 14 February 2013 - 11:00 AM
0.o
So out of curiosity I tried running my code on a computer. Started getting syntax errors. Fixed all the syntax errors and re did the sections as suggested. Now it's working.
I find it pretty strange that the turtle wasn't giving me syntax errors.
818 posts
Posted 14 February 2013 - 11:49 AM
What syntax errors did you get?
7 posts
Posted 14 February 2013 - 03:51 PM
I don't remember the exact errors, but basically it was a couple simple things like forgetting the parentheses on turtle.forward() and misspelled a variable reference, both in the new_layer function.
This is the new version that is working.
http://pastebin.com/FWVFQg6zOn a side note, I didn't consider how horribly inefficient this script is on fuel. Right now it goes through twice as much as it should.
I'm thinking going around in a box should be fairly simple to implement and be much more fuel efficient.