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

Item Share Program, Noob Needs Help C:

Started by Finnnicus, 03 January 2013 - 01:03 AM
Finnnicus #1
Posted 03 January 2013 - 02:03 AM
-This program is meant to evenly arrange items among slots 13-16, any help appreciated…
and help with posting etiquette…
and help with learn to write CC Lua well…
and thats all.


total=0
each=0

for i=13, 16 do
turtle.select(i)
  total=total+turtle.getItemCount(i)
print(total)
end

g=13
for g=13, 16 do
turtle.select(g)
turtle.transferTo(g+1)
g=g+1
end
--The main problem IS HERE
turtle.getItemCount(16) = sharenum*4

for k=13, 16 do
turtle.select(16)
turtle.transferTo(k, sharenum)
end

[Fixed code tags. -L]
Doyle3694 #2
Posted 03 January 2013 - 02:44 AM
I think you are looking for

sharenum = turtle.getItemCount(16)*4
InputUsername #3
Posted 03 January 2013 - 03:22 AM
Also, and this may be off-topic, but your code tags are broken, the second one should be instead of
.
remiX #4
Posted 03 January 2013 - 06:48 AM
You have not defined sharenum yet. Put sharenum = 0 at the top.

Also your second for loop, you do not need to have a set variable to begin with, or increment it each time:


for g =13, 16 do
    turtle.select(g)
    turtle.transferTo(g+1)
end
Finnnicus #5
Posted 03 January 2013 - 02:23 PM
Ok thanks guys!
But I need to stop The 'g' and 'k' loops from running past 16, because there is no slot 17, any help?
Thx Remix, that was stupid to manually increment a for loop. *facepalm*
remiX #6
Posted 03 January 2013 - 10:01 PM
How so and are you sure? Add a print(k) in the loop to check what it goes up to


for k=13, 16 do
print("k is now " .. k)
turtle.select(16)
turtle.transferTo(k, sharenum)
end
Finnnicus #7
Posted 04 January 2013 - 12:54 AM
made an inconvenient work around(to use slots 12-15 instead), ill try this

EDIT:
still doesnt work, doesnt even get to the print, just says slot 17 out of range.
hmmm