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

[Lua][Question]I don't know why this doesn't work?

Started by aileron565, 22 December 2012 - 08:15 AM
aileron565 #1
Posted 22 December 2012 - 09:15 AM
Any help is appreciated! :)/>

term.clear()
term.setCursorPos(1,1)
turtle.select(1)
function newslot()
  x = x + 1
  turtle.select(x)
end
function checkslot()
  if turtle.getItemCount() < 1 then
  newslot()
end
print("How Far:")
input = read("*")
for d = 1, input, 1 do
  if turtle.detectDown() then
	turtle.forward()
  else
	for s = 1, 9, 1 do
	  checkslot()
	end
turtle.placeDown()
  end
end
OmegaVest #2
Posted 22 December 2012 - 09:40 AM
The only problem I see is that you never close the checkslot function.

Also, why are you checkslotting nine times in a row? It will always choose the same slot,

Checkslot would be better this way:

function checkslot()
   for i = 1, 16 do
      if turtle.getItemCount(i) > 1
         turtle.select(i)
         print("Got new slot.")
         return true
      end
   end
   return false
end


And then work to make it so if false, the program stops.
ChunLing #3
Posted 22 December 2012 - 12:21 PM
Post your error messages. Also, what you're trying to accomplish, and what happens instead.

You never initialize x. Thus "x = x + 1" is an error.
aileron565 #4
Posted 22 December 2012 - 07:33 PM
Post your error messages. Also, what you're trying to accomplish, and what happens instead.

You never initialize x. Thus "x = x + 1" is an error.
How do you initialize x?
ChunLing #5
Posted 22 December 2012 - 07:53 PM
You assign it a value that is not itself based on x. Like: x = 0

In this particular case, you should just use Pixeltoast's function, since that eliminates the need for the newslot function which was causing an error.

If you have other errors after fixing this one, please post the error message and describe any undesired behavior.
aileron565 #6
Posted 23 December 2012 - 04:39 AM
You assign it a value that is not itself based on x. Like: x = 0

In this particular case, you should just use Pixeltoast's function, since that eliminates the need for the newslot function which was causing an error.

If you have other errors after fixing this one, please post the error message and describe any undesired behavior.
One more question. How do you make an if statement activate when turtle.detect() is not true.
Doyle3694 #7
Posted 23 December 2012 - 05:31 AM
if not turtle.detect() then