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

how to send variables over rednet

Started by dcleondc, 03 April 2012 - 01:38 AM
dcleondc #1
Posted 03 April 2012 - 03:38 AM
i have a program that i made to mine a tunnel that is a 3x3x5 for 1 section and when i start the program it will ask me how many sections i want, but i would like to start it form my main base using rednet. here is the code for the tunnel.

shell.run("clear")
print("How many sections do you want?1 section=5 blocks!")
input = read()
num = tonumber(input)
for i=1, num do
print("mineing a tunnel!")
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.down()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.down()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.down()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.down()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.digUp()
turtle.up()
turtle.dig()
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.down()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnLeft()
turtle.up()
turtle.turnRight()
turtle.place()
turtle.turnLeft()
turtle.down()
end
shell.run("clear")
print("Done!")
print("Do you want to run this program again?")
print("y or n")
y = io.read()
if y == "y" then
shell.run("mine")
else
shell.run("shutdown")
end
but i want to know how i would activate this using rednet from a computer that is in my main base, i know a little about computercraft but i dont know how to use rednet so please help.
Luanub #2
Posted 03 April 2012 - 03:49 AM
For one I would clean this up a little, try adding a for loop to replace some of the repetition.

In order to start the function remotely you will need to add in something like the following..

Base Computer

rednet.send( 1, "starttunnel")


Mine Computer

local evt, id, msg = os.pullEvent("rednet_message")
if msg == "starttunnel" then
starttunnel()
end

this is very basic but hopefully gives you an idea of what you will need to accomplish. In order for this to work you will need to convert your code into a function within the code and name it "starttunnel". If you do it right you can even pass arguments dictating the size of the tunnel.
dcleondc #3
Posted 03 April 2012 - 03:59 AM
For one I would clean this up a little, try adding a for loop to replace some of the repetition.

In order to start the function remotely you will need to add in something like the following..

Base Computer

rednet.send( 1, "starttunnel")


Mine Computer

local evt, id, msg = os.pullEvent("rednet_message")
if msg == "starttunnel" then
starttunnel()
end

this is very basic but hopefully gives you an idea of what you will need to accomplish. In order for this to work you will need to convert your code into a function within the code and name it "starttunnel". If you do it right you can even pass arguments dictating the size of the tunnel.
is there a way to make it so i can select how many sections i want? if so how?
Luanub #4
Posted 03 April 2012 - 04:05 AM
You will have to setup your "starttunnel" function to accept an argument.

So

function starttunnel( num )
num = num or 1
rest of code
end

You would then have to pass the argument in the rednet message and capture it in the msg var as a string, then split the string to separate the date on the mine computer.

I'm not to where I could play with/test this or I would give you a better example.