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

Please Help this program.

Started by norway240, 02 September 2012 - 02:07 AM
norway240 #1
Posted 02 September 2012 - 04:07 AM
So all i want this program to do is on one computer be able to send a message to a turtle and have the turtle receive that message and it will run that program. So what i have works with sending commands with no args. for example: you send the message: help. and the turtle will run the program: help. But if you send the message: help programs, then it says: No such program.. Here is the code i've written:

Client (program on the turtle) :

while true do
rednet.open("right")
x,y,z=rednet.receive()
print(y)
shell.run(y)
end

Server (program on the computer) :

while true do
write"Command: "
input = read()
rednet.open("top")
rednet.broadcast(input)
end
Matrixmage #2
Posted 02 September 2012 - 04:11 AM
try making x,y,z into x, y, z , I don't know if that would help, it might though, I've seen some people have problems with having their syntax like that
dcleondc #3
Posted 02 September 2012 - 04:13 AM
it should be input = io.read() not input = read()
Matrixmage #4
Posted 02 September 2012 - 04:18 AM
I've never noticed that making a difference, don't know if that as anything to do with me using 1.3 (tekkit) rather then 1.4
dcleondc #5
Posted 02 September 2012 - 04:23 AM
you can do read()? because i always use io.read()
Matrixmage #6
Posted 02 September 2012 - 04:38 AM
you can do read()? because i always use io.read()
ya, I've always used "read()" didn't know about "io.read()" until a few days ago
dcleondc #7
Posted 02 September 2012 - 04:38 AM
code for console

id = 17 --replace with id of your turtle
rednet.open("right")
print("what program do you want to run?")
program = io.read()
rednet.send(id, program)
code for turtle

rednet.open("right")
while true do
    local x, y, z = rednet.recive(timeout)
    shell.run(y)
end
Matrixmage #8
Posted 02 September 2012 - 04:39 AM
I think that "read()" is from the OS API but I'm not sure
norway240 #9
Posted 02 September 2012 - 05:44 AM
code for console

id = 17 --replace with id of your turtle
rednet.open("right")
print("what program do you want to run?")
program = io.read()
rednet.send(id, program)
code for turtle

rednet.open("right")
while true do
	local x, y, z = rednet.recive(timeout)
	shell.run(y)
end
Still does the same thing. when i type in: refuel. then it refuels but when i do: refuel all. then it says no such program.
dcleondc #10
Posted 02 September 2012 - 06:12 AM
thats because refuel all is not a program, refuel is and when you type all it is a arg and you cant send args with how i did it
norway240 #11
Posted 02 September 2012 - 06:20 AM
thats because refuel all is not a program, refuel is and when you type all it is a arg and you cant send args with how i did it
i know. the thing is i was wondering how you could send args. do you know how you can?
dcleondc #12
Posted 02 September 2012 - 06:38 AM
console

id = 17
rednet.open("right")
print("what program do you want to run")
program = io.read()
print("what arg do you want to send")
arg = io.read()
rednet.send(id, program)
rednet.send(id, arg)
shell.run("startup")
turtle

rednet.open("right")
while true do
    local x, y, z = rednet.receive(timeout)
    local x, y, z = rednet.receive(timeout)
    shell.run(y,a)
end
Zoinky #13
Posted 02 September 2012 - 02:30 PM
Try this
run it on a turtle and a computer.
Spoiler

local sSide = "top" -- side that moden is on computer
term.clear() -- clear screen
term.setCursorPos(1,1) -- sets cursos position to top left
if turtle then -- test if it is a turtle
rednet.open("right")
while true do -- starts loop
  local event,arg1,arg2,arg3 = os.pullEvent("rednet_message")
  pcall( function()
	local tWords = {}
	for match in string.gmatch(arg2, "[^ \t]+") do
	 table.insert( tWords, match )
	end
	for i = 1,#tWords do
	 if tonumber(tWords[i]) then
	 tWords[i] = tonumber(tWords[i])
	 end
	end
	shell.run(unpack(tWords))
   end
  )
end -- end of loop
else -- if not a turtle then
rednet.open(sSide)
while true do
  rednet.broadcast(read())
end
end

Had the same problem a little while ago. This worked :D/>/> All credit goes to BigSHinyToys. You can run it on both the computer and turtle.
BigSHinyToys #14
Posted 02 September 2012 - 02:37 PM
this is odd I was looking for that thread and was going to copy the code here. I was ninjaed :D/>/> with my own code lol XD . Any questions about the code ask and I will explain.