Jump to content




Whats wrong with my function?


  • You cannot reply to this topic
5 replies to this topic

#1 Zamithal

  • Members
  • 28 posts

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

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

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


#3 Zamithal

  • Members
  • 28 posts

Posted 25 December 2012 - 04:15 PM

thank you, that worked.

#4 Zamithal

  • Members
  • 28 posts

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.

#5 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 December 2012 - 05:44 PM

Well, loc:forward up at the top needs parentheses. Most of the rest of it looks fine.

#6 Zamithal

  • Members
  • 28 posts

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users