8 posts
Posted 19 September 2012 - 12:23 AM
Okay, so I'm writing a program to build a house, however I'm running into the problem of running out of the material it is building. I want to program it to check if the current slot is empty before it continues placing blocks, and if it is to switch to the next slot. Here's the code I have to try to check the contents of the slot(Probably horribly wrong):
turtle.getItemCount(1)
if ItemCount==0 then
turtle.select(2)
else
write("slot still filled")
end
This doesn't work however, when nothing is in slot 1 it doesn't switch slots, also is there a way to say getItemCount of the currently selecte slot? Thanks for the help. If you want to see the program I am trying to insert it into, I can provide it.
3790 posts
Location
Lincoln, Nebraska
Posted 19 September 2012 - 12:41 AM
You never defined Itemcount. You should do do ItemCount = turtle.getItemCount(1)
8 posts
Posted 19 September 2012 - 12:56 AM
You never defined Itemcount. You should do do ItemCount = turtle.getItemCount(1)
. . . I should have caught that, I'll try it, thanks. Do you know of a way to tell it to just check the selected slot rather than a specificly defined slot?
3790 posts
Location
Lincoln, Nebraska
Posted 19 September 2012 - 01:00 AM
No, with the Turtle API, you have to specify which slot. Take a look at the Turtle API wiki
here.
8 posts
Posted 19 September 2012 - 02:13 AM
No, with the Turtle API, you have to specify which slot. Take a look at the Turtle API wiki
here.
Okay, I was just wondering.
1 posts
Posted 21 February 2013 - 02:20 AM
you could do it so
z = 1 – slot number
turtle.getItemCount(z)
if turtle.getItemCount(z) == 0 then
z = z + 1
turtle.selcect(z) – z = 2 now so it will change it to the second slot
else
write("slot has blocks in")
end
2088 posts
Location
South Africa
Posted 21 February 2013 - 02:43 AM
for i = 1, 16 do
if turtle.getItemCount(i) == 0 then
print( "Slot " .. i .. " is empty")
else
print( "Slot " .. i .. " has items")
end
end
199 posts
Location
Switzerland
Posted 21 February 2013 - 03:22 AM
I would do something like this (not tested)
currentslot = 1
local function selectit(s)
turtle.select(s)
currentslot = s
end
local function checkslot(c)
if turtle.getItemCount(c) == 0 then
selectit(currentslot +1)
else
print( "Current slot still has items")
end
end
Instead of turtle.select() u use selectit in your program so you always know which slot is currently selected
to test this just use checkslot(currentslot)
Greets Loki