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

auto installer

Started by compaman, 15 April 2013 - 04:12 AM
compaman #1
Posted 15 April 2013 - 06:12 AM
I made a great computer-controled wheat farm, and placed the terminal in my house. So 3 days ago, i made an os for all the turtles…
But then i wondered how i could put this program on all my turtles… So i copied it into a txt file and put it in the programs driectory. Now i would like to know wether theres another way, something like an auto installer, so you can take the program from the terminal-computer and send it via rednet to all turtles, which auto install it…
I tried it like that, but somehow, it didn't work:

id, msg = rednet.receive()
shell.run("edit blahlblah")
print(msg)

is this possible?
SuicidalSTDz #2
Posted 15 April 2013 - 06:23 AM
rednet.open("right")
local id, message = os.pullEvent("rednet_message")

This is your first problem, rednet.receive is a function call, not an event. You also never opened up the turtles modem on the right.

EDIT: I'll leave this here
http://www.computercraft.info/wiki/Rednet_%28API%29
compaman #3
Posted 15 April 2013 - 06:35 AM
thanks for your fast answer, but my proble is that i want to install a mesage or whatever
Sorry that i forget to say that these 3 lines are only a little part of my testprogram, i opened the rednet already. Sorry for that
I wanted to know if a message or whatever can install itself, also open the lua or edit console and writes itself.
os.pullEvent( target-event ) Blocks until the computer receives an event
and
rednet.receive(timeout) Waits until it received a rednet message or timeout has passed. Leave args empty to wait for a message forever.
are teh same, or not?
both wait for an input(in this case a rednet message), or?!
SuicidalSTDz #4
Posted 15 April 2013 - 06:38 AM
You mean write a message to a file?
compaman #5
Posted 15 April 2013 - 06:55 AM
i mean get a message/ broadcast and write it into a program file… like an auto installer… you get the program code and install it
think thats what you mean too… ;)/>
SuicidalSTDz #6
Posted 15 April 2013 - 06:56 AM
Here, replace yourFileName with the name of the file you are reading from and writing to:

--[[Main Computer]]--
rednet.open("right")
readFrom = "yourFileName"
computerID = receivingComputersID
local program = {}
local file = fs.open(readFrom,"r")
local lines = file.readLine()
for lines in file.readLine do
 table.insert(program,lines)
end
file.close()
local data = textutils.serialize(program)
rednet.send(computerID,data)

--[[Turtle program]]--
rednet.open("right")
local writeTo = "yourFileName"
local _, id, message = os.pullEvent("rednet_message")
local data = textutils.unserialize(message)
local file = fs.open(writeTo,"w")
for i = 1,#data do
 file.writeLine(data[i])
end
file.close()
SuicidalSTDz #7
Posted 15 April 2013 - 06:58 AM
Of course, you can change the rednet.send to rednet.broadcast.

EDIT: The turtles must be running the receive program before the send program is ran from the main computer. Oh and you'll have to change the rednet.open("right") to the side your modem is on.
compaman #8
Posted 15 April 2013 - 07:17 AM
I think thats the right way, but i get
textutils:177: attemp to concatenate string and nil
on the turtle
do you know whats false?
SuicidalSTDz #9
Posted 15 April 2013 - 07:33 AM
Umm? I tried the code myself on a normal computer and it worked fine.. Let me see your current code. For the turtle and main computer.

EDIT: Did you replace rednet.send with rednet.broadcast? If so, you will need to get rid of the computer ID:

rednet.broadcast(data) instead of rednet.send(computerID,data)
compaman #10
Posted 15 April 2013 - 07:50 AM
sorry, tried to upload pictures, but somehow my computer too dumb for that
but believe me, i typed in the same like in your example…
compaman #11
Posted 15 April 2013 - 07:54 AM
ahh… sorry, hadn'T noticed that…
compaman #12
Posted 15 April 2013 - 08:05 AM
ahh, somehow it works, but the program doesn't start.
if i type in the name of the program in the turtle, the curser jump into the next line, thats all
so it seems like the computer has the program, because he doesn't write "no such programm" but theres only an "print("")" in the code…
SuicidalSTDz #13
Posted 15 April 2013 - 08:20 AM
Ok, run the receive program on the turtle. Does it sit without a bliking cursor?

Now run the computer send program. It should go straight to the next line if successful.

Now go back to the turtle, it should now have a blinkinig cursor on the next line.

Now click the turtle and edit the writeTo file (writeTo is a variable) If you did not change the writeTo variable to something else, the data will be saved in a file called yourProgramName.

If the file is still empty then I want you to edit the readFrom file on your main computer, if there is nothing in it, then that is the reason. Also, if you did not change the readFrom file variable to your file name, then it is reading a non-existant file.

In order for this to work you MUST change these two variables:

local readFrom = "yourFileName" – where yourFileName is the file you are reading from on the main computer
local writeTo = "yourFileName" – where yourFileName is the file that is being written to on the turtle

So let's try an example where i'm reading from the file 'test' on the main computer and I will receive it's contents in a file named 'test' on the turtle:

--[[Main Computer]]--
local readFrom = "test"
rednet.open("right")
local program = {}
local file = fs.open(readFrom,"r")
local lines = file.readLine()
for lines in file.readLine do
 table.insert(program,lines)
end
file.close()
local data = textutils.serialize(program)
rednet.broadcast(data)
--[[Turtle program]]--
local writeTo = "test"
rednet.open("right")
local _, id, message = os.pullEvent("rednet_message")
local data = textutils.unserialize(message)
local file = fs.open(writeTo,"w")
for i = 1,#data do
 file.writeLine(data[i])
end
file.close()
compaman #14
Posted 15 April 2013 - 08:39 AM
Sorry Sorry sorry that i have to bother you again :(/> , but i typed in exactly the same as in you code, and write a new test file with a simple print code, but it won't work
Everyithing is like youve said…
but when i try to start the program on my turtle, the cursor only goes into a new line…
is it exactly the same code you posted like the code you used in minecraft?
SuicidalSTDz #15
Posted 15 April 2013 - 08:41 AM
The cursor is supposed to go into a new line. That indicates that the event was fired and the message was received from the main computer. All the data from the file in the main computer is now stored in the writeTo file.

I want you to edit the receive program and at the bottom of the code type:

print(writeTo)

Save this then run the receive program and then run the send program on the main computer.

Go back to the turtle, there should be a word on the screen. This will tell you where your data is stored on the turtle. Edit this file and all the data from the main computer should be there.
compaman #16
Posted 15 April 2013 - 08:46 AM
no i mean when i try to start the program on the turtle, i just received…
normaly, when you want to start a program which is not installed on your computer comes a red writing: "no such program"
but when i try to open the program i just received, he goes into a new line…
The computer knows the name of the program but theres no code anymore
SuicidalSTDz #17
Posted 15 April 2013 - 08:52 AM
Can you paste the code you are trying to copy from the computer to the turtle for me?
compaman #18
Posted 15 April 2013 - 08:54 AM
ahh, i made a program on the turtle called "lol" (code was print("hallo"))
into your code i wrote writeTo("lol")
at the main computer i made a program called "test" (code was print("mmddmm"))
into your code i wrote readFrom("test")
so test must overwrite lol
if i now tried to start lol at the turtle, the curser jumped only in a new line, too
that means that the code that is received from the turtle is nil OR the turtle failed "translating" the code
SuicidalSTDz #19
Posted 15 April 2013 - 08:57 AM
So this is what your code looks like?

--[[Main Computer]]--
local readFrom = "test"
rednet.open("right")
local program = {}
local file = fs.open(readFrom,"r")
local lines = file.readLine()
for lines in file.readLine do
 table.insert(program,lines)
end
file.close()
local data = textutils.serialize(program)
rednet.broadcast(data)
--[[Turtle program]]--
local writeTo = "lol"
rednet.open("right")
local _, id, message = os.pullEvent("rednet_message")
local data = textutils.unserialize(message)
local file = fs.open(writeTo,"w")
for i = 1,#data do
 file.writeLine(data[i])
end
file.close()
compaman #20
Posted 15 April 2013 - 08:58 AM
yes
SuicidalSTDz #21
Posted 15 April 2013 - 09:02 AM
Ok, so this should read from the file "test" on the main computer and send it to the turtle, the turtle will then write all the data from the computer and save it in a file called "lol". When you run lol on the turtle, does it print 'hallo'?
compaman #22
Posted 15 April 2013 - 09:04 AM
nope thats my problem… it only jump into the next line…
SuicidalSTDz #23
Posted 15 April 2013 - 09:06 AM
Ok, lets try this.

Run the receive program on the turtle, then run the send program on the computer. Go to the turtle and type:

edit lol

You should see the words:

print("hallo")

If you don't see these words, exit out of the turtle and go to the main computer and type:

edit test

You should see the words:

print("mmdmm")
compaman #24
Posted 15 April 2013 - 09:08 AM
No, theres nothing at all checked that already…
compaman #25
Posted 15 April 2013 - 09:10 AM
But the file at the main computer is ok…
SuicidalSTDz #26
Posted 15 April 2013 - 09:14 AM
Ok, so the problem is at the main computer from what I can tell. At the end of the sending program on the computer type:

local debug = textutils.unserialize(programs)
for k,v in pairs(debug) do
print(v)
end

Save this, now run the send program without running the receive program. Do you see any words?
compaman #27
Posted 15 April 2013 - 09:21 AM
Will check that out tommorow, but now i'll go to a friend…
Till tomorrow…
And thank you for your help, your genius, really
SuicidalSTDz #28
Posted 15 April 2013 - 09:24 AM
Will check that out tommorow, but now i'll go to a friend…
Till tomorrow…
And thank you for your help, your genius, really
No problem. It's why i'm here ^_^/>
compaman #29
Posted 16 April 2013 - 02:13 AM
so, i just checked it out and there was actually a red writing:

textutils:177: attempt to conatenate string and nil

so thats exactly the same what the turtle said before i wrote

rednet.broadcast(data) (before i wrote data into the bracket there just standed rednet.broadcast() think that meant i broadcsted nothing and when the turtle tried to decode the message there weren't anything)

so i think youre right with your supposition the fail is at the main computer…
but i swear, i typed in exactly the same you posted… :huh:/>
compaman #30
Posted 16 April 2013 - 08:41 PM
EDIT: the same error when i put nothing in the bracket after

textutils.serialize
LordIkol #31
Posted 17 April 2013 - 02:54 AM
Hey together hope you dont mind i step into this but while reading this topic i may found a little bug in the debugging Suicide posted.

assuming that this is your code:

So this is what your code looks like?

--[[Main Computer]]--
local readFrom = "test"
rednet.open("right")
local program = {}
local file = fs.open(readFrom,"r")
local lines = file.readLine()
for lines in file.readLine do
table.insert(program,lines)
end
file.close()
local data = textutils.serialize(program)
rednet.broadcast(data)
–snip–

the debug should be like this i think.



local debug = textutils.unserialize(data)
for k,v in pairs(debug) do
print(v)
end

for me this is working

another thing i may ask is if you are playing on a server or local?
PixelToast #32
Posted 17 April 2013 - 03:06 AM
you dont need to use readLines
use readAll to grab the whole file as a string
then you can use file.write() to write the data back
much much easier
compaman #33
Posted 17 April 2013 - 06:13 AM
so finally got it…
heres my code…

—main computer—
local readFrom = "blabla"
rednet.open("right")
local file = fs.open(readFrom, "r")
local lines = file readLine()
local program = {lines}
for lines in file.readLine do
table.insert(program, lines)
end
file.close()
local data = textutils.serialize(program, lines)
rednet.broadcast(data)

—receiver—
the code fromSuicidalSTDz was correct at all…

Thanks to all people who answered and
special thanks to SuicidalSTDz for giving me the main code… he's an awsome guy… ;)/> :P/>

regards, compaman