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

Wireless Turtle Help

Started by habnef3, 23 August 2015 - 02:29 AM
habnef3 #1
Posted 23 August 2015 - 04:29 AM
Hi, I'm having trouble with making programs that let me execute commands wireless from a computer to a turtle.

I have the following program for the computer
Spoilerrednet.open("right")
term.write("Command: ")
message1=io.read()
rednet.broadcast(message1)
print(command1)

and this one is for the turtle.

Spoilerrednet.open("right")
rednet.receive()
shell.run(message1)
print(message1)

When ran the main computer seems the be working fine, but the turtle just shows a blank line and then ends.
All help is appreciated.
HPWebcamAble #2
Posted 23 August 2015 - 06:52 AM
I think you swapped the two pieces of code.
But I believe I see the problem:

The turtle might have something like this:

rednet.open("right")

term.write("Enter Command: ")
local cmd = read() --# 'local' makes the variable only part of this program. Its good practice. 'read()' is likely the same as 'io.read()' but slightly shorter

rednet.broadcast( cmd )

The problem is in your computer code
It should look like this:

rednet.open("right")

local id , msg = rednet.recieve() --# Assigns the id of the sender and the msg to these local variables

shell.run( msg ) --# HUGE security flaw - runs any command it gets! But ok for experimenting

You might notice that you have to run the program on the turtle and the computer everytime you want this to work.
You can solve this problem with a loop:
http://www.lua.org/pil/4.3.2.html