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

CCC(Computer Craft Communicator)[CC V1.31][Program Version 2.0]

Started by SquareMan, 27 March 2012 - 12:40 AM
SquareMan #1
Posted 27 March 2012 - 02:40 AM
I created a new thread for all my scripts, it can be found here: http://www.computercraft.info/forums2/index.php?/topic/3266-cc-v141squares-scripts-cccomunicator-and-more/

Computer Craft Communicator, or CCC, is a program, or 3 programs actually, I have developed that interact with each other.

You can send messages to other computers and turtles and even call programs for them to run.
To use a terminal must have a modem, and turtles must be wireless.
The Computer/Turtle your sending to must be currently running the receive program for it to receive commands.
the code,

send
Spoiler

function menu()
local n = 1
while true do
local x, y = term.getCursorPos()
term.clearLine()
if n == 1 then
  write("[YES]   NO")
else
  write("YES   [NO]")
end
term.setCursorPos(x, y)
a, b = os.pullEvent()
while a ~= "key" do
  a, b = os.pullEvent()
end
if b == 203 and n == 2 then n = 1 end
if b == 205 and n == 1 then n = 2 end
if b == 28 then
  print("")
  break
end
end
if n == 1 then return true end
if n == 2 then return false end
return false
end
function programSelect(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("Select a program[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
function modemSideSelect(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("What side is your modem on?")
print("Select a side[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
------------------------------------------------------------------------------------------------------------
print("Are You Calling A Program?")
local choice = menu()
local sides = {"Right", "Back", "Left", "Front", "Top", "Bottom"}
local modemSide = modemSideSelect(sides)
if modemSide == 1 then
rednet.open("right")
elseif modemSide == 2 then
rednet.open("back")
elseif modemSide == 3 then
rednet.open("left")
elseif modemSide == 4 then
rednet.open("front")
elseif modemSide == 5 then
rednet.open("top")
elseif modemSide == 6 then
rednet.open("bottom")
end

print("What ID is your Turtle/PC?")
ID = io.read() --Find the ID of the receiving Turtle/PC
ID = tonumber(ID)
if choice == true then
print("Are You Sending To a Turtle?")
local choice2 = menu()
if choice2 == true then
  while true do
   local programs = {"Excavate", "Tunnel", "Lumberjack", "Dance", "Move", "Exit"}
   local program = programSelect(programs)
   if program == 1 then
	info = "Excavate"
	rednet.send(ID, info)
	local TID, question = rednet.receive(10)
	if TID == ID then
	 print(question)
	 info2 = io.read()
	 rednet.send(ID, info2)
	else
	 print("Out-of-Range or Interferance, try again later.")
	end
   elseif program == 2 then
	info = "Tunnel"
	rednet.send(ID, info)
	local TID, question = rednet.receive(10)
	if TID == ID then
	 print(question)
	 info2 = io.read()
	 rednet.send(ID, info2)
	else
	 print("Out-of-Range or Interferance, try again later.")
	end
   elseif program == 3 then
	info = "Lumberjack"
	rednet.send(ID, info)
   elseif program == 4 then
	info = "Dance"
	rednet.send(ID, info)
   elseif program == 5 then
	local dirs = {"Right", "Back", "Left", "Forward", "Up", "Down", "Back"}
	while true do
	 local dir = programSelect(dirs)
	 if dir == 1 then
	  info = "right"
	  rednet.send(ID, info)
	 elseif dir == 2 then
	  info = "back"
	  rednet.send(ID, info)
	 elseif dir == 3 then
	  info = "left"
	  rednet.send(ID, info)
	 elseif dir == 4 then
	  info = "forward"
	  rednet.send(ID, info)
	 elseif dir == 5 then
	  info = "up"
	  rednet.send(ID, info)
	 elseif dir == 6 then
	  info = "down"
	  rednet.send(ID, info)
	 elseif dir == 7 then
	  break
	 end
	end
   elseif program == 6 then
	break
   end
  end
else
  local programs = {DJ}
  local program = programSelect(programs)
  if program == 1 then
   info = "DJ"
   rednet.send(ID, info)
  end
end
else
term.write("Info to send:")
local info = io.read() --Gather the info/program to send/run
end
if choice == false then
rednet.send(ID, info) -- Send the info
end

receive(Terminal Version)
Spoiler

function modemSideSelect(m)
n=1
l=#m
while true do
term.clear()
term.setCursorPos(1,2)
for i=1, l, 1 do
if i==n then print(i, " ["..m[i].."]") else print(i, " ", m[i]) end
end
print("What side is your modem on?")
print("Select a side[arrow up/arrow down]")
a, b= os.pullEventRaw()
if a == "key" then
if b==200 and n>1 then n=n-1 end
if b==208 and n<=l then n=n+1 end
if b==28 then break end
end
end
term.clear() term.setCursorPos(1,1)
return n
end
----------------------------------------------------------------------------------------------------
while true do
local sides = {"Right", "Back", "Left", "Front", "Top", "Bottom"}
local modemSide = modemSideSelect(sides)
if modemSide == 1 then
rednet.open("right")
elseif modemSide == 2 then
rednet.open("back")
elseif modemSide == 3 then
rednet.open("left")
elseif modemSide == 4 then
rednet.open("front")
elseif modemSide == 5 then
rednet.open("top")
elseif modemSide == 6 then
rednet.open("bottom")
end
print("Now Listening forever for a message, press Ctl+T to exit")
id, message = rednet.receive() -- listen indefinatly for a message
if message == "DJ" then
shell.run("dj")
else
print("Incoming Info From PC/Turtle #",id)
print("Info:")
print(message)
end
end

receive(Turtle Version)
Spoiler

while true do
rednet.open("right") -- open ports so the turtle can "hear"
print("Now Listening forever for a message, press Ctl+T to exit")
id, message = rednet.receive() -- listen indefinatly for a message
if message == "Excavate" then
rednet.send(id, "Radius:")
local id2, answer = rednet.receive(10)
if id2 == id then
  answer = tonumber(answer)
  shell.run("Excavate ", answer)
else
  print("Out-of-Range or Interferance, try again later.")
end
elseif message == "Tunnel" then
rednet.send(id, "How Far?")
local id2, answer = rednet.receive(10)
if id2 == id then
  answer = tonumber(answer)
  shell.run("Tunnel ", answer)
else
  print("Out-of-Range or Interferance, try again later.")
end
elseif message == "Lumberjack" then
shell.run("Lumberjack")
elseif message == "Dance" then
shell.run("Dance")
elseif message == "right" then
turtle.turnRight()
turtle.forward()
elseif message == "back" then
turtle.back()
elseif message == "left" then
turtle.turnLeft()
turtle.forward()
elseif message == "forward" then
turtle.forward()
elseif message == "up" then
turtle.up()
elseif message == "down" then
turtle.down()
else
print("Incoming Info From PC/Turtle #",id)
print("Info:")
print(message)
end
end

Current programs you can call:
Turtles:

Move
Excavate
Tunnel
Lumberjack(Must have Tikiana's Lumberjack Script or other lumberjack program)
Dance

Terminals:
DJ

More Program Options to come!

I also made a modified version of Tikiana's Lumberjack Script that replants the tree when its done being cut down if there is a sapling in the bottom right corner of the turtle inventory.
Code,
Spoiler

while turtle.detect() do
print("Chopping")
turtle.dig()
turtle.digUp()
print("Moving")
turtle.up()
end
while not turtle.detect() and not turtle.detectDown() do
print("Moving down")
turtle.down()
print("Job done!")
programHasRan = 1
end
if programHasRan == 1 then
turtle.select(9)
turtle.place()
end

Download(If you cant/don't want to copy paste)
[attachment=133:CCCommunicator V2.0.zip]

Feel free to leave comments and suggestions in the replies!

Change Log
SpoilerV 2.0
SpoilerAdded Turtle movement controls
Added modem side select instead of typing
Minor Changes to program select engine
Modified Tikiana's Lumberjack Script
Wolvan #2
Posted 27 March 2012 - 11:23 PM
you can call dance? Can U stop it too via rednet? I encountered that problem at the beginning of my remote controlled turtle program
SquareMan #3
Posted 28 March 2012 - 01:23 AM
You cant stop it yet, i'd probally need to edit the Dance program itself because once it starts a program using shell.run it doesn't resume the program until the program you called stops, in the next version you will be able to move the turtle remotely, and call another program without having to run the "receive" program again. This is also my first program i made from the ground up using the knowledge i gained from tutorials.
Wolvan #4
Posted 29 March 2012 - 08:18 AM
Yeah I created a remote controlled turtle program and I had to create a custom dance program too :o/>/> Now the dance program is running on the controller PC. That way all connected turtles move the same time and the same way
SquareMan #5
Posted 29 March 2012 - 07:16 PM
Thats cool, BTW, in the next version you will be able to move the turtle remotely too!
Wolvan #6
Posted 30 March 2012 - 01:54 PM
Thats cool, BTW, in the next version you will be able to move the turtle remotely too!
Did that already but your version seems to have a nice communication system ;:o/>/>
SquareMan #7
Posted 30 March 2012 - 04:14 PM
Thanks glad to see some people like it
binary_block #8
Posted 31 March 2012 - 02:37 PM
can someone tell me how to add the program i just downloaded it but i have no idea where place it please help
SquareMan #9
Posted 04 April 2012 - 01:26 AM
can someone tell me how to add the program i just downloaded it but i have no idea where place it please help
sorry for a late reply but you have to go to your .minecraft folder and in it go into mods and then ComputerCraft
then go to lua/rom/programs
then place send in there and place the terminal version of the receive in the computer folder and the turtle version of the receive in the turtle folder.
or if you download the .zip file

copy and paste everything in the zip file in the .minecraft/mods/ComputerCraft/lua/rom/programs folder.