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

Remote script updating via rednet?

Started by kylezffz, 02 June 2013 - 03:14 AM
kylezffz #1
Posted 02 June 2013 - 05:14 AM
Alright… So this may sound totally insane, but don't judge me. :P/>
I've got just over 500 wireless mining turtles in a sugar cane farm… And, I want them all to be relatively server crash-resistant. So, I have a very simple script that only involves them turning, and the script runs on startup. Harvests are executed via rednet.

So, here's the issue though…. I quickly realized that updating the programs on these turtles would be… more than a slight hassle. And I was just wondering… Would there be a way, via rednet, to send the turtles a new pastebin code to download as startup? And then somehow include that receiving code in the existing startup program?

Any help you can offer is greatly appreciated.
Thank you!
Engineer #2
Posted 02 June 2013 - 05:37 AM
I think you should go into the .minecraft folder -> saves -> <your wold> -> computercraft and then you have to place the program in each of the turtle's ID. I hope they are in a range like 1 - 500, otherwise you have to come up to each turtle to find out wich ID it has. But if you have to come up to that turtle, then you can do the pastebin thing..

Why do you need so much sugarcane? :o/>
Bomb Bloke #3
Posted 02 June 2013 - 07:46 AM
I get the impression that whenever a turtle runs a script, that script gets loaded into server RAM until it's complete. Or at least, I can make modifications to my scripts with an external text editor while my turtle is running them and that doesn't appear to break them.

That means that your turtles can probably delete their own scripts, rewrite them, then reboot themselves. But really it'd be safer to use a triple script setup: "startup", "harvest" and "update".

"startup" could search for and call the "harvest" script, and if it's not on the turtle, instead call the "update" script.

The "harvest" script could sit and wait for rednet signals. If it gets a signal telling it to harvest, it does so, or if it gets a signal telling it to update, it could likewise call the "update" script.

The "update" script could start out by deleting the "harvest" script, assuming it's on the turtle. It'd then create a "temp" script (deleting it first if it already existed) and get ready to start writing lines to it (see fs.open).

The server could be rigged so that you could either bulk update your turtles - in which case, it broadcasts an "update" signal to all of them - or so that individual turtles could request updates whenever they want them.

Whenever a turtle connected to it for an update, it'd perform a quick handshake (send messages back and forth confirming what that turtle wants), then wait a few seconds. If another turtle tried to connect in that time it'd handshake with that and wait longer, and so on, until about five seconds pass with no handshakes occurring.

It'd then start broadcasting the new script a line at a time, ending with the "end of data" code (which can be anything you like, so long as you code the turtles to recognise what it is). Once the turtles got that, they'd rename the "temp" script to "harvest" and run it. In this way, if anything goes wrong during the update process (say the server reboots), when the affected turtles restarted they'd immediately bug the update server for a fresh copy instead of becoming inoperable.

… Anyway, while fun to code, I suspect you'd be better off with one turtle managing the field. One way is to wall the whole thing off, and when the turtle reboots, it'd fly above the cane and fly towards a wall. When it hit it, it'd turn and fly towards the adjacent wall, and when it hit THAT it would know it was in a corner of the field. From there it could lower itself into the cane again and resume the harvest in an orderly manner.
Engineer #4
Posted 02 June 2013 - 08:06 AM
And maybe you could put the program into ~/.minecraft/mods/computercraft/rom/programs/turtle/. That way you only have to modify your rom everytime you update.