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

Whats wrong with my function?

Started by Zamithal, 25 December 2012 - 02:54 PM
Zamithal #1
Posted 25 December 2012 - 03:54 PM

function fillSlot(slot) -- finish the stack
  until turtle.getItemSpace(slot) == 0 -- repeat until stack is complete
	turtle.select(slot) -- select slot
	turtle.suck() -- try to fill slot
	if turtle.getItemSpace(slot) == 0 then -- if slot was filled
	  turtle.suckDown() -- pick up all non matching items
	  for i = 1, 16 do --empty all items except for kept slots
		if i == 1 or i == 4 or i == 13 or i == 15 or i == 16 then -- kept slots
	   -- Do nothing
	 else
	   turtle.select(i) -- select non-kept slot
	   turtle.drop()	--place in chest
	 end
	  end
	else -- if slot was not filled
	  for i = 1, 16 do  --empty all items into "temporary holding area" except for kept slots
		if i == 1 or i == 4 or i == 13 or i == 15 or i == 16 then -- kept slots
	   -- Do nothing
	 else
	   turtle.select(i) -- select non-kept slots
	   turtle.dropDown() -- drop on floor (under turtle)
	 end
   end
	end
  end
end
fillSlot(1)


The error is Line 2 'end' expected to close function, but i believe I have all the ends
Luanub #2
Posted 25 December 2012 - 04:02 PM
You start out line 2 with until but there is no repeat in front of it.

Repeat loops work like this..

repeat
--this code
until condition is met

--so this would continue until item space for slot 1 == 0
repeat
turtle.suck()
until turtle.getItemSpace(1) == 0
Zamithal #3
Posted 25 December 2012 - 04:15 PM
thank you, that worked.
Zamithal #4
Posted 25 December 2012 - 05:14 PM
Got another function that i cant find the issue with, though posting it here again would be better than starting a new thread:


function farmLine() -- farm 1 collum
    repeat
   loc:forward
    until turtle.detect() == true
repeat
   turtle.select(14)
   if turtle.compareDown() == true then
	 loc:right()
  loc:right()
  loc:forward()
  loc:left()
  loc:left()
  turtle.dig()
  turtle.select(1)
  turtle.place()
   else
	 loc:right()
  loc:right()
  loc:forward()
  loc:left()
  loc:left()
until loc.x == 0
repeat
   loc:left()
until loc.h == 2
end

the loc: comands are from Lyqud's location API and there isn't a problem with those.
Error is: line 7 function arguments expected.
Lyqyd #5
Posted 25 December 2012 - 05:44 PM
Well, loc:forward up at the top needs parentheses. Most of the rest of it looks fine.
Zamithal #6
Posted 25 December 2012 - 06:16 PM
Wow, that's the second time I've done something silly like that. thank you for the help.