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

"If" statement math

Started by SYELDARB, 25 February 2014 - 12:32 PM
SYELDARB #1
Posted 25 February 2014 - 01:32 PM
i'm a slopy programer, if it works i do it i dont care if there is a better way.

i'm writeing a simple code to take nugets (from Tinkers Construcs ore berry bushes) and useing a advanced crafty turtle. even out the nugets in slots 6,7,8,10,11,12,14,15,16. then craft them into ingots.

Is there a way i could only pull out of the chest a amount divisible of 9? or some other way to do it.

(sorry about the spelling)

Here Is What I Have So Far
———————————-

local g = 6

function Sort()
turtle.select(6)
turtle.suckUp(9)
for i=6,8 do
turtle.transferTo(i,1)
end
for u=10,12 do
turtle.transferTo(u,1)
end
for y=14,16 do
turtle.transferTo(y,1)
end
end

function Drop()
for i=1,16 do
turtle.select(i)
turtle.drop()
end
end

(this is the part i need help with)

if turtle.getItemCount(g) == 9 then
Sort()
elseif turtle.getItemCount(g) == 18 then
Sort()
Sort()
elseif turtle.getItemCount(g) == 27 then
Sort()
Sort()
Sort()
end

(thats what i started and i could work but i'm sure that there is a better way(and i dont want to type the same thing over and over))


Drop()
turtle.select(1)


If you can help thanks!
Lyqyd #2
Posted 25 February 2014 - 01:46 PM

--# select slot, suck items
turtle.select(1)
turtle.suckUp()

--# drop back anything over a multiple of nine
turtle.dropUp(turtle.getItemCount(1) % 9)

--# spread items
local count = turtle.getItemCount(1) / 9
turtle.transferTo(2, count)
turtle.transferTo(3, count)
for i = 5, 7 do
  turtle.transferTo(i, count)
end
for i = 9, 11 do
  turtle.transferTo(i, count)
end

--# craft items.
turtle.select(4)
turtle.craft(count)
SYELDARB #3
Posted 26 February 2014 - 12:26 AM
cool thanks, i didnt know that you could do something like this
turtle.dropUp(turtle.getItemCount(1) % 9)
civilwargeeky #4
Posted 26 February 2014 - 04:00 AM
Also, in case you didn't know, the " % " means modulus, same thing as remainder. So "4 % 3" is 1 because 4/3 = 1 remainder 1, "5 % 3" is 2 and so on.
Just thought I'd point that out.