This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jakemg's profile picture

quick question

Started by jakemg, 04 April 2013 - 02:19 PM
jakemg #1
Posted 04 April 2013 - 04: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?
Sammich Lord #2
Posted 04 April 2013 - 04:20 PM
You could use a loop:

for i=1, 16 do
  turtle.select(1)
  turtle.dropUp()
end
SuicidalSTDz #3
Posted 04 April 2013 - 04:25 PM
You could use a loop:

for i=1, 16 do
  turtle.select(1)
  turtle.dropUp()
end
Ehem, turtle.select(i) not turtle.select(1) ^_^/>
Sammich Lord #4
Posted 04 April 2013 - 04:30 PM
You could use a loop:

for i=1, 16 do
  turtle.select(1)
  turtle.dropUp()
end
Ehem, turtle.select(i) not turtle.select(1) ^_^/>
I have been on IRC for 11 hours :P/> Can't think while tired :P/>
SuicidalSTDz #5
Posted 04 April 2013 - 04:37 PM
You could use a loop:

for i=1, 16 do
  turtle.select(1)
  turtle.dropUp()
end
Ehem, turtle.select(i) not turtle.select(1) ^_^/>
I have been on IRC for 11 hours :P/> Can't think while tired :P/>
Yeah, I know the feeling :P/>
jakemg #6
Posted 04 April 2013 - 04:47 PM
I keep getting error :1: do expected but i am using
while (turtle.detect)) do
whats the problem??
Kingdaro #7
Posted 04 April 2013 - 04:52 PM
It should be

while turtle.detect() do
  -- your code here
end
A good attention to detail usually helps.
jakemg #8
Posted 04 April 2013 - 04:54 PM
Thx
jakemg #9
Posted 04 April 2013 - 05: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??
PonyKuu #10
Posted 04 April 2013 - 05:33 PM
That exactly what your code do:


turtle.placeUp(1)
place up the chest


for i=1,16 do
and 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.

end
End 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()
Zoinky #11
Posted 04 April 2013 - 05: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
jakemg #12
Posted 04 April 2013 - 05:41 PM
okay so now im using this code


local args = {...}
local times = tonumber(args[1]) -- this is how many times we want to run the program

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


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


turtle.turnLeft()
turtle.turnLeft()
end


for i=1, times do
turtle.forward()


end


but all that it does is just spin around "x" amount of times it doesnt even dig wtf???
Kingdaro #13
Posted 04 April 2013 - 05: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".


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.
jakemg #14
Posted 04 April 2013 - 07: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
Shnupbups #15
Posted 04 April 2013 - 07: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
Lyqyd #16
Posted 05 April 2013 - 05: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.