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

Prototype sorting system problem

Started by popdog15, 15 April 2013 - 12:27 PM
popdog15 #1
Posted 15 April 2013 - 02:27 PM
So, basically, I'm having a sorting system where a turtle is facing 3 barrels, so it can turn left or right to access any of them. It then turns around and puts them into a pipe. Simple enough.
I'm (trying to) control this with a computer + modem, which just is

rednet.open("top")
tArgs = {...}
rednet.broadcast(tArgs[1])
rednet.broadcast(tArgs[2])


I don't need it to send to the specific computers, because these will be the only wireless ones in the area.

The turtles code is this:

rednet.open("right")
turtle.select(1)
  local senderId, msg = rednet.receive()
  local senderId, amount = rednet.receive()
   if msg == "cbl" then
	turtle.turnLeft()
	turtle.suck()
	 if turtle.getItemCount(1) > tonumber(amount) then
	  newamount = turtle.getItemCount(1) - amount
	   turtle.drop(newamount)
	 elseif turtle.getItemCount(1) < tonumber(amount) then
	  turtle.select(2)
	  turtle.suck()
	   if turtle.getItemCount(2) + turtle.getItemCount(1) > tonumber(amount) then
	  newamount = turtle.getItemCount(2) + turtle.getItemCount(1) - tonumber(amount)
	 turtle.drop(newamount)
	 end
	end
	end

That's where the problem lies. I've seen it turn, but it will not suck any items, and it gives no errors. The program just stops. Any idea why that is?

I'll post a picture of what it looks like if you ask for it. Its pretty cheap to do if it works out :D/>

Oh, and the only reason I have cbl for cobble set up is that its just a prototype. I'd get more things set up if it works.
Spongy141 #2
Posted 15 April 2013 - 07:07 PM
Try changing the sending computers code to

rednet.open("top")
term.write("Amount: ")
local amount = read()
term.write("Password: ")
local msg = read()
rednet.broadcast(msg)
sleep(0.2)
rednet.broadcast(amount)
Then make sure the turtle sleeps 0.2 seconds before it receives the amount.
Also did you really say … for the message? and I don't see any part were your control computer lets you input an amount.
popdog15 #3
Posted 16 April 2013 - 10:42 AM
Spongy, I did because in the instance of just getting the base code working I just wanted to type in "broadcast *item* *amount*" not having to input one amount, press enter, input another, press enter again.

You know if you do tArgs (or any other name) = {…} it uses the arguments after the program name?
For example, what I do currently, is just "broadcast cbl 5." Thats the input.
popdog15 #4
Posted 16 April 2013 - 10:43 AM
Oh, and I figured out the problem. The turtles were pulling from the front of a barrel, and, you can't do that. Has to be the bottom. But a new problem has showed up, if I do 65 for the amount, it will only have a stack of 64 in slot one.
Spongy141 #5
Posted 16 April 2013 - 11:13 AM
^
put.

if amount > 64 then
  --Put code to switch the another stack
end
EDIT: If you want it to remember which slot it should use next do.

slot = <slot number inside the turtles inventory>
slot = slot +1
--So then you would have the turtle select the slot.  If you get the starting slot not being used, have it the starting slot - 1 from its original value.
popdog15 #6
Posted 16 April 2013 - 11:46 AM
Thanks man!