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

Turtle Program only goes to the second slot when out of blocks, doesn't switch to third and so on

Started by n1ghtk1ng, 05 January 2013 - 06:49 AM
n1ghtk1ng #1
Posted 05 January 2013 - 07:49 AM
I made a turtle program to make a platform levels for my "factory" in Feed-The-Beast. Every time it runs out of blocks in a slot, I wanted it to switch to the next slot, but it only switches from the first slot to the second slot. How can I fix this?

--[[ VARIABLES ]]--

--[[ FUNCTIONS ]]--

function woodSlot()
a = 1
local b = turtle.getItemCount(a)
if b == 0 then
  a = a+1
  turtle.select(a)
end
end

--[[ MAIN CODE ]]--
while true do
if turtle.back() == true then
  turtle.place()
elseif turtle.back() == false then
  turtle.turnRight()
end
woodSlot()
end
Viproz #2
Posted 05 January 2013 - 07:51 AM
every time you run the woodSlut function you reset the value to 1, define a = 1 in the "–[[ VARIABLES ]]–" !
remiX #3
Posted 05 January 2013 - 07:54 AM
move a = 1 out of the woodSlot() function, it keeps resetting to 1 and then if the amount in slot a is 0 it increases it but then resets back to 1


--[[ VARIABLES ]]--

--[[ FUNCTIONS ]]--
a = 1
function woodSlot()

local b = turtle.getItemCount(a)
if b == 0 then
  a = a+1
  turtle.select(a)
end
end

--[[ MAIN CODE ]]--
while true do
if turtle.back() == true then
  turtle.place()
elseif turtle.back() == false then
  turtle.turnRight()
end
woodSlot()
end
n1ghtk1ng #4
Posted 05 January 2013 - 08:37 AM
move a = 1 out of the woodSlot() function, it keeps resetting to 1 and then if the amount in slot a is 0 it increases it but then resets back to 1


--[[ VARIABLES ]]--

--[[ FUNCTIONS ]]--
a = 1
function woodSlot()

local b = turtle.getItemCount(a)
if b == 0 then
  a = a+1
  turtle.select(a)
end
end

--[[ MAIN CODE ]]--
while true do
if turtle.back() == true then
  turtle.place()
elseif turtle.back() == false then
  turtle.turnRight()
end
woodSlot()
end
Well that was stupid of me! Thanks!