Jump to content




How to automatically go to the next slot


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

#1 Moortexz

  • New Members
  • 1 posts

Posted 17 December 2012 - 10:45 AM

Hello everybody!
First of all, sorry for my bad English.
I am currently working on a program that builds a wall for my house. But I don't want to refill it every second so I need a code that automatically goes to the next slot when the first slot is empty. I tried it but with no success. Can someone help me?
Thanks :)

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 10:47 AM

try using an if statement with turtle.getSlotCount() which returns how many items are in the slot. then just use turtle.select() to change the slot.

#3 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 10:52 AM

View PostTheOriginalBIT, on 17 December 2012 - 10:47 AM, said:

try using an if statement with turtle.getSlotCount() which returns how many items are in the slot. then just use turtle.select() to change the slot.

it's
turtle.getItemCount(slotNum)
;)

This shouldn't be that difficult. Have a variable that stores the current slot it uses and before each place have an if statement like this:
itemCount = turtle.getItemCount(slotNum)
if itemCount == 0 then
    slotNum = slotNum + 1
    turtle.select(slotNum)
end
-- Then the placing the blocks code here

This should work, give it a try and give us the feedback :)

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 11:01 AM

View PostremiX, on 17 December 2012 - 10:52 AM, said:

View PostTheOriginalBIT, on 17 December 2012 - 10:47 AM, said:

try using an if statement with turtle.getSlotCount() which returns how many items are in the slot. then just use turtle.select() to change the slot.

it's
turtle.getItemCount(slotNum)
;)

sorry for the quick typing, typo :P

#5 billysback

  • Members
  • 569 posts

Posted 17 December 2012 - 11:04 AM

you could make it loop;
local function getSlot(min, start)
	if min == nil then min = 0 end
	if start == nil then start = 1 end
	for i=start,16 do
		if turtle.getSlotCount(i) >= min then return i end
	end
	return -1
end
Usage would be:
local slot = getSlot()
this would get the first of any slot to have above 0 items, or -1 if none was found (using defaults)

or:
local slot = getSlot(minimumItemCount, startingSlotNumber)


#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 11:15 AM

View PostTheOriginalBIT, on 17 December 2012 - 11:01 AM, said:

View PostremiX, on 17 December 2012 - 10:52 AM, said:

View PostTheOriginalBIT, on 17 December 2012 - 10:47 AM, said:

try using an if statement with turtle.getSlotCount() which returns how many items are in the slot. then just use turtle.select() to change the slot.

it's
turtle.getItemCount(slotNum)
;)

sorry for the quick typing, typo :P

A typo is a typing error/mistake. You just didn't know what it was :P So I wouldn't call it a typo ;)

Sorry if this sounds cocky xD

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 11:18 AM

View PostremiX, on 17 December 2012 - 11:15 AM, said:

View PostTheOriginalBIT, on 17 December 2012 - 11:01 AM, said:

View PostremiX, on 17 December 2012 - 10:52 AM, said:

View PostTheOriginalBIT, on 17 December 2012 - 10:47 AM, said:

try using an if statement with turtle.getSlotCount() which returns how many items are in the slot. then just use turtle.select() to change the slot.

it's
turtle.getItemCount(slotNum)
;)

sorry for the quick typing, typo :P

A typo is a typing error/mistake. You just didn't know what it was :P So I wouldn't call it a typo ;)

Sorry if this sounds cocky xD

I use it all the time. i think i know how to use it.

And in normal size. Sorry if this sounds cocky xD ... but I dont care :P

#8 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 December 2012 - 11:24 AM

Well read the link to typo... Am I not right? uhuh

#9 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 11:29 AM

lets just agree to disagree or call it a lapse in judgement or something and move on, and stop clogging up this with nothing





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users