Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (fs.exists("choices") == false) then --Check if this is first time run, no saved choices on file
- while true do
- print("Number of slots to be filled before emptying(1-16):")
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= 16) then
- slots=answerv
- --print("Crop ", croplist[answerv], " chosen")
- break
- else
- print("-Wrong answer, input does not match range of choices-")
- end
- end
- end
- while true do
- print("Stacksize of items(1-64):")
- local answer = read()
- if tonumber(answer)==nill then
- print("-Wrong answer, input not a number-")
- else
- local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
- if (0 < answerv and answerv <= 64) then
- stacksize=answerv
- --print("Crop ", croplist[answerv], " chosen")
- break
- else
- print("-Wrong answer, input does not match range of choices-")
- end
- end
- end
- --Write choices to file
- local file = fs.open("choices","w")
- file.writeLine("slots="..tostring(slots))
- file.writeLine("stacksize="..tostring(stacksize))
- file.close()
- end
- os.loadAPI("choices") -- Reads choices from file
- local slots= choices.slots
- local stacksize= choices.stacksize
- --slots=14 --Number of slots to be filled before emtying
- --stacksize=64
- local function empty()
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- while true do
- local emptyslot=0
- local maxcount=0
- for i=1,16 do
- if turtle.getItemCount(i)==0 then
- emptyslot=emptyslot+1
- elseif turtle.getItemCount(i)>maxcount then
- maxcount=turtle.getItemCount(i)
- end
- end
- if (emptyslot <= (16-slots) and maxcount>= 0.75*stacksize) then
- empty()
- elseif emptyslot==0 then
- empty()
- end
- sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement