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

Interacting Computer and Turtle via Rednet

Started by Obsidia, 20 August 2015 - 01:09 PM
Obsidia #1
Posted 20 August 2015 - 03:09 PM
Hello guys,

Im currently working on a little setup in my base.
I want a turtle to check the item amount in a chest and send the number to a computer which prints it on a monitor but I have no idea how to do that..




currently i am that far:

turtle code so far:


-- Startup for the turtle:
rednet.open("right")
while true do
  id, message = rednet.receive()
	 if id == 5 then
	 if message = Cobbleanzahl -- Anzahl is german for amount. Dont mind that
	 shell.run("Anzahl")
	 end
  end
end


-- The "Anzahl" code that gets the item count
-- priniting on the turtle(( How do I get the monitor to print that?))
print("Wird gezaehlt!")	-- german for "getting amount/counting"
-- functions
local Anzahl = turtle.getItemCount()
-- Those lines are those who get the amount
turtle.suck()	
sleep(1)
-- HERE's my question: How do I get the monitor to print that via rednet?
print("Anzahl:"..Anzahl)
sleep(1)
turtle.drop()	
--


Computer code:

-- startup:
--open up modem
rednet.open("right")
-- select the 2 monitors
m = peripheral.wrap("top")   -- the monitor that shows the amount(if possible)
ml = peripheral.wrap("left")  -- the touchscreen monitor to run the programs

-- functions  ( those are only for the computer)
local id = os.getComputerID()
local name = os.getComputerLabel()
-- settings for monitors, text etc
term.setBackgroundColor(colors.blue)  ( No i dont want to clear it. i just want it to be blue on the text itself)
print("ID:"..id)			
print("Name:"..name)
term.setBackgroundColor(colors.black)
print("Wie kann ich dir helfen?")  -- german for "how can I help you?"
-- my monitor setup
m.setBackgroundColor(colors.blue)
ml.setBackgroundColor(colors.black()
-- the stuff for the touchscreen is comming in here I guess.(I can do that myself)



-- cobbleamount program to let the turtle run the program
rednet.send(8, Cobbleanzahl)
-- Now what I think should be what gets the job done together with
-- the turtle to get the amount to the computer
while true do
id, message = rednet.receive()
   if id == 8 then
	  if message ==  



now.. theres my problem… how do I tell the turtle to send the correct number to the computer and then how to get the computer to print the number to the top monitor?



thanks for the help! :)/>
Edited on 20 August 2015 - 01:18 PM
HPWebcamAble #2
Posted 20 August 2015 - 09:20 PM
First open the modems on the turtle and computer:

rednet.open( "right" ) --# Make sure the side is correct on each

The computer needs to listen for messages.

local id , message = rednet.receive() --# The 'id' is the id of the computer (or turtle) that sent the message

--# After the message is received, you can do what you'd like with it.
print( message )

To send a message:

rednet.broadcast( "hi" )

--# Or in your case:
rednet.broadcast( turtle.getItemCount() )
Edited on 20 August 2015 - 07:21 PM
Obsidia #3
Posted 20 August 2015 - 10:13 PM
Going to test it out a bit//
Edited on 20 August 2015 - 08:15 PM