Posted 04 April 2012 - 03:50 AM
So ive been trawling through the forums all night trying to figure this out. Its currently 3.36am and I have work at 9 :)/>/>
So im hoping somone can help.
I have a program with arguements on my turtle called boremaster <argument>
So as an example if i run up to my turtle and type boremaster 20 it digs a tunnel 3x3 for 20 blocks forward.
Now the plan is to send commands to this turtle via rednet from my comfy datacentre. But alas ive yet to be able to call custom programs via rednet.
Ive tried the following:
[Computer]
command = 'print ("Hello world")'
rednet.open("right")
rednet.broadcast(command)
id, mess = rednet.receive()
print (mess)
[Turtle]
rednet.open("right")
id, mess = rednet.receive()
a = loadstring(mess)
a() – i know that will run it
print (a()) – print it?
rednet.broadcast(a()) – should send results..
Which was helpfully on the forums already. I can get my turtle to print no problem but when I do somthing like:
[Computer]
command = 'boremaster 20'
rednet.open("right")
rednet.send(45,command)
[Turtle]
rednet.open("right")
id, mess = rednet.receive(40)
a = loadstring(mess)
a() – i know that will run it
I get the error: attempt to call nil
Ive no idea whats going on here. Could someone please give me some advice on what to do with this?
Thanks
PS here is the boremaster code: (feel free to use it, I know its not fantastic but im trying to learn)
So im hoping somone can help.
I have a program with arguements on my turtle called boremaster <argument>
So as an example if i run up to my turtle and type boremaster 20 it digs a tunnel 3x3 for 20 blocks forward.
Now the plan is to send commands to this turtle via rednet from my comfy datacentre. But alas ive yet to be able to call custom programs via rednet.
Ive tried the following:
[Computer]
command = 'print ("Hello world")'
rednet.open("right")
rednet.broadcast(command)
id, mess = rednet.receive()
print (mess)
[Turtle]
rednet.open("right")
id, mess = rednet.receive()
a = loadstring(mess)
a() – i know that will run it
print (a()) – print it?
rednet.broadcast(a()) – should send results..
Which was helpfully on the forums already. I can get my turtle to print no problem but when I do somthing like:
[Computer]
command = 'boremaster 20'
rednet.open("right")
rednet.send(45,command)
[Turtle]
rednet.open("right")
id, mess = rednet.receive(40)
a = loadstring(mess)
a() – i know that will run it
I get the error: attempt to call nil
Ive no idea whats going on here. Could someone please give me some advice on what to do with this?
Thanks
PS here is the boremaster code: (feel free to use it, I know its not fantastic but im trying to learn)
Spoiler
--Boremaster5000 coded by Nicholas John aka Festivejelly feel free to steal my code but gimmie credit yo.
local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: tunnel <length>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local intTunnelLength = tonumber( tArgs[1] )
if intTunnelLength < 1 then
print( "Tunnel length must be positive" )
return
end
intDistanceTravelled=0
--Functions
local function beginMining(str)
for i = 1, intTunnelLength do
--Dig out the centre column
turtle.dig()
sleep(0.6)
while turtle.detect() do
turtle.dig()
sleep(0.6)
end
turtle.forward()
turtle.digUp()
sleep(0.6)
while turtle.detectUp() do
turtle.digUp()
sleep(0.6)
end
turtle.up()
turtle.digUp()
sleep(0.6)
while turtle.detectUp() do
turtle.digUp()
sleep(0.6)
end
turtle.up()
--dig out the left column
turtle.turnLeft()
turtle.dig()
sleep(0.6)
while turtle.detect() do
turtle.dig()
sleep(0.6)
end
turtle.down()
turtle.dig()
turtle.down()
turtle.dig()
turtle.forward()
turtle.back()
--dig out the right column
turtle.turnRight()
turtle.turnRight()
turtle.forward()
turtle.dig()
sleep(0.6)
while turtle.detect() do
turtle.dig()
sleep(0.6)
end
turtle.up()
turtle.dig()
sleep(0.6)
while turtle.detect() do
turtle.dig()
sleep(0.6)
end
turtle.up()
turtle.dig()
sleep(0.6)
while turtle.detect() do
turtle.dig()
sleep(0.6)
end
turtle.down()
turtle.down()
turtle.forward()
turtle.back()
turtle.turnLeft()
intDistanceTravelled=intDistanceTravelled+1
end
end
local function backToStart()
if intDistanceTravelled == 0 then
print(newline)
write("Error No blocks to mine")
print(newline)
else
for j = 1, intDistanceTravelled do
turtle.back()
end
end
print(newline)
write("Mission completed")
print(newline)
end
beginMining()
backToStart()