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

Send details from Mining Turtle to Computer

Started by MrDikke, 27 March 2015 - 11:14 AM
MrDikke #1
Posted 27 March 2015 - 12:14 PM
I have a Mining Turtle setup, but its sometimes deep under the ground. And when I want to know at what percentage it is, i need to go find it.

Now I want to send this to a Computer. Is this possible?
I currently just have it displayed on the screen.

But I can't find out how I could sent this to the Computer.

Thanks in advance!
Lupus590 #2
Posted 27 March 2015 - 05:34 PM
Look into the rednet API
TechedZombie #3
Posted 27 March 2015 - 09:30 PM
well you need to use a wireless turtle and attatch a wireless modem to your computer and then open the modem by using "rednet.open("modem_side")" then "rednet.send(ComId, "Message")" and use rednet.receive() to wait for a rednet messgae and then you can check what id it is from ex:
rednet.open("top")



rednet.open("top")
local depth = 50
while true do
  rednet.send(45, depth)
end

Btw U can send strings variables and a raw string. Also rednet.receive returns id then message so use [ id, msg = rednet.receive() ]
Edited on 27 March 2015 - 08:31 PM
MrDikke #4
Posted 28 March 2015 - 11:05 AM
Thanks,
but now I have set this up
Spoiler

p = peripheral.wrap("right")
range = 1000
rednet.open("back") --assuming modem is on top

local function receiveRednet()
local p1, p2 = rednet.receive()
return p2
end

local function checkForMessage()
event, player, message = os.pullEvent("chat") -- Now you got the event, which player, and which message.

if message == ("status") then
	p.say(current, range, true, "Wood Turtle")
end
end

while true do
	if receiveRednet() == true then
		current = p2
	end
	print(current)
	checkForMessage()
end

But I can't get it to work, its sending it to the computer (which runs the program above), but the computer doesn't do anything.
Any help?

EDIT: I know what's wrong; it keeps checking for messages. But I only want it to check for messages for a few seconds how can I do this?
Edited on 29 March 2015 - 01:09 PM
Lyqyd #5
Posted 30 March 2015 - 04:21 PM
Change your code to use a single event handling loop instead:


while true do
  local event = {os.pullEvent()}
  if event[1] == "chat" then
    --# handle chat events
  elseif event[1] == "rednet_message" then
    --# handle rednet messages.
  end
end
MrDikke #6
Posted 29 April 2015 - 10:34 AM
Thanks, sorry for the late response.

Vacation etc. :D/>