15 replies to this topic
#1
Posted 04 April 2013 - 03:19 PM
Is there a code for my turtle just to drop all its items in to a chest?
because right now i am having to cycle the turtle.select(1) then going to (2) then (3) ect. is there away for me just to go
turtle.placeUp()
turtle.dropUp() then just have it drop all its items up?
because right now i am having to cycle the turtle.select(1) then going to (2) then (3) ect. is there away for me just to go
turtle.placeUp()
turtle.dropUp() then just have it drop all its items up?
#2
Posted 04 April 2013 - 03:20 PM
You could use a loop:
for i=1, 16 do turtle.select(1) turtle.dropUp() end
#4
#5
#6
Posted 04 April 2013 - 03:47 PM
I keep getting error :1: do expected but i am using
while (turtle.detect)) do
whats the problem??
while (turtle.detect)) do
whats the problem??
#7
Posted 04 April 2013 - 03:52 PM
It should be
while turtle.detect() do -- your code here endA good attention to detail usually helps.
#8
Posted 04 April 2013 - 03:54 PM
Thx
#9
Posted 04 April 2013 - 04:21 PM
Sorry i found the probelm to my original problem but i cant edit title but my problem now is that how can i make it run my turtle script x amount of times because right now i have it set to while turtle.detect() do but how do i make it so that when i go to run my turtle (my script is called test) i type test x then it runs it x amount of time??
#10
Posted 04 April 2013 - 04:33 PM
That exactly what your code do:
It seems you should end the loop earlier.
Also, turtle.placeUp (1) doesn't work like you want it to work. It should be
turtle.select(1)
turtle.placeUp()
turtle.placeUp(1)place up the chest
for i=1,16 doand for each slot
turtle.select(i) turtle.dropUp() turtle.digUp() turtle.suck()drop items from the slot, DIG THE CHEST, and for some reason suck items from somewhere.
endEnd the loop.
It seems you should end the loop earlier.
Also, turtle.placeUp (1) doesn't work like you want it to work. It should be
turtle.select(1)
turtle.placeUp()
#11
Posted 04 April 2013 - 04:33 PM
local function empty() if turtle.getItemCount(16) < 15 then turtle.select(1) turtle.placeUp() for i = 1, 16 do turtle.select(i) turtle.dropUp() end turtle.select(1) turtle.digUp() end end
#12
Posted 04 April 2013 - 04:41 PM
okay so now im using this code
but all that it does is just spin around "x" amount of times it doesnt even dig wtf???
local args = {...}
local times = tonumber(args[1]) -- this is how many times we want to run the program[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]for i=1, times do
function dig()
turtle.select(1)
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.digDown()
turtle.down()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.up()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.digDown()
turtle.down()
end[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]function empty()
if turtle.getItemCount(16) >15 then
turtle.placeUp(1)
for i=1,16 do
turtle.select(i)
turtle.dropUp()
turtle.select(1)
end
turtle.digUp()
end
end[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]
turtle.turnLeft()
turtle.turnLeft()
end[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]
for i=1, times do
turtle.forward()[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]end
[/color][/font]
[font="helvetica, arial, sans-serif"][color="#282828"]but all that it does is just spin around "x" amount of times it doesnt even dig wtf???
#13
Posted 04 April 2013 - 04:55 PM
For the record, you can change your title if you use the full editor. There should be a button for it when you edit your post. Try to stick to one topic.
On the subject of the matter, extra parameters are stored in a special notation, "...", which can then be converted to a table for use, by surrounding it in curly brackets, then giving it a variable for a home. Most people call this variable "args" or "tArgs".
For example, typing "test foo bar baz" would run the program "test", storing foo, bar, and baz in the args table. We can print each of these arguments individually:
For your specific problem, "x" would be the first in the args table. In order to use it, however, we have to convert it to a number, since all arguments that come in are strings, which don't work well with math. After that, you simply use a for loop.
The extra information isn't completely necessary, but should be helpful to know for the future.
On the subject of the matter, extra parameters are stored in a special notation, "...", which can then be converted to a table for use, by surrounding it in curly brackets, then giving it a variable for a home. Most people call this variable "args" or "tArgs".
local args = {...}
For example, typing "test foo bar baz" would run the program "test", storing foo, bar, and baz in the args table. We can print each of these arguments individually:
print(args[1]) --> foo print(args[2]) --> bar print(args[3]) --> baz
For your specific problem, "x" would be the first in the args table. In order to use it, however, we have to convert it to a number, since all arguments that come in are strings, which don't work well with math. After that, you simply use a for loop.
local args = {...}
local times = tonumber(args[1]) -- this is how many times we want to run the program
for i=1, times do
-- your code
end
The extra information isn't completely necessary, but should be helpful to know for the future.
#14
Posted 04 April 2013 - 06:00 PM
thx i am just starting (as you ropably know) and you have been helping me alot i now have a fully functional ender chest tunnel creator Thanks so much
#15
Posted 04 April 2013 - 06:51 PM
To answer your second problem, you would need arguments. Do it like so:
local args = {...} -- Get arguments and put them into the 'args' table
if args[2] then -- If the program is used incorrectly
print("Usage: test [times]") -- Help the user on how to correctly use it
error() -- Quit
end
if not args[1] then -- If no amount is supplied
local n = 1 -- Set to run 1 time
else -- Otherwise if an amount IS supplied
local n = tonumber(args[1]) -- Set it to run that many times
end
for i = 1,n do -- Start the loop
<code> -- Insert your code here
end
#16
Posted 05 April 2013 - 04:16 AM
Threads merged. Stick to one topic for multiple questions about the same piece of code, please. Do not clutter up the forums like that.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












