4 posts
Posted 22 December 2012 - 10:58 AM
Okay I was playing on FTB and was working w/ my mining turtle. to test what i learned so far w/ turtles i made a small program called towerUp.you type towerUp and then how tall you want it. ex: towerUp 10so I input towerUp 10 and let it run. It only places three blocks before quitting.if you can help me, here's the code:
local args = { ... }
local i = 0
while #args .= i do
turtle.place()
turtle.up()
i = i + 1
end
4 posts
Posted 22 December 2012 - 11:05 AM
someone please help me…
818 posts
Posted 22 December 2012 - 11:09 AM
#args will return how many values there are inside the table args, rather than giving a value, so you are probably getting something unexpected.
.= is actually not an operator. I think what you are looking for is ~= (not equal to)
Also, this is a bad use of while loops, I would recommend a for loop instead.
So abit better syntax would be:
local args = { ... }
local i = 0
args[1] = tonumber(args[1]) -- anything from args will be strings, so we need them to be numbers before doing maths with them
for i = 1,args[1] do
turtle.place()
turtle.up()
end
Tell me if you get any problems and we will work them out further.
8543 posts
Posted 22 December 2012 - 11:10 AM
local args = {...}
if #args < 1 then
print("specify height")
return
end
for i = 1, tonumber(args[1]) do
turtle.place()
turtle.up()
end
for i = 1, tonumber(args[1]) do
turtle.down()
end
818 posts
Posted 22 December 2012 - 11:12 AM
Oh wow, Lyqyd, look at you post count! 1337!
2088 posts
Location
South Africa
Posted 22 December 2012 - 11:13 AM
You got the args part right. 'args' in your program is a table now which contains your arguments for when you start the program. You entered 10 as your first argument so args[1] would equal 10.
local args = { ... }
local dist = tonumber(args[1]) -- Takes the number, and now as it is a string you need to convert it to a number
for i = 1, dist do
turtle.up()
turtle.placeDown() -- Places down, just using turtle.place() places forwards
end
Edit: Left this tab open for too long :P/> Ninja'd by 4 mins, haha
818 posts
Posted 22 December 2012 - 11:14 AM
I double ninjad! Where is me bloody medal?
4 posts
Posted 22 December 2012 - 11:19 AM
#args will return how many values there are inside the table args, rather than giving a value, so you are probably getting something unexpected.
.= is actually not an operator. I think what you are looking for is ~= (not equal to)
Also, this is a bad use of while loops, I would recommend a for loop instead.
So abit better syntax would be:
local args = { ... }
local i = 0
args[1] = tonumber(args[1]) -- anything from args will be strings, so we need them to be numbers before doing maths with them
for i = 1,args[1] do
turtle.place()
turtle.up()
end
Tell me if you get any problems and we will work them out further.
oops .= i forgot i changed that to >= i messed up
818 posts
Posted 22 December 2012 - 11:21 AM
OK, is it working now, with updated code?
Also, forgot to say, ask any questions if I was unclear or I left something unexplained.
4 posts
Posted 22 December 2012 - 11:25 AM
thanks doyle it works now :D/>
2088 posts
Location
South Africa
Posted 22 December 2012 - 11:28 AM
Nevermind, just derped and didn't read the name of the posts :P/> and then quoted doyle