15 posts
Location
Microscopic Village in Nebraska.
Posted 03 November 2016 - 03:21 AM
Hello,
I have essentially zero code to show. What I'm attempting to do is send a message to a preset channel via modem.transmit(…), and I need everything (including getting the id of the active, operating computer/turtle to be passed in as replyChannel) automatically, as in requiring zero user input.
The only way my research found to get the ID of the active computer was via the ID default program.
If there is a way to grab the ID of the active computer via some handy line of code, that would be preferred, but I would be OK with extracting the ID from the output of the ID program, if I knew how to redirect the output!
My question is:
What is the best way to automatically determine the ID of the active computer, without any user input? That is, if there is no handy API available, how could I run the ID program and redirect its output towards a String for processing?
Thanks!
The Hermanoid
P.S.
Seriously. No User Input. After the program starts, user interaction ends, with no exceptions.
1220 posts
Location
Earth orbit
Posted 03 November 2016 - 03:33 AM
What you're looking for is
os.getComputerID
local computerID = os.getComputerID()
7083 posts
Location
Tasmania (AU)
Posted 03 November 2016 - 04:21 AM
By the way, if you want to know how a given ComputerCraft script (such as "id") does its thing, you could always just read that script's source. Mirrors such as
this one make it pretty easy to get at.
2427 posts
Location
UK
Posted 03 November 2016 - 11:05 AM
is there a reason you are partially replicating rednet and not using rednet?
15 posts
Location
Microscopic Village in Nebraska.
Posted 11 November 2016 - 03:58 AM
Kind of. I'm not dead set on a method for doing this yet, if you have suggestions. The issue is, I'm (planning on) having masses of turtles pop into existence with no idea where they came from, and they all need to get an idea where they came from, and what they need to do.
It'd go something like this:
1. Master Computer "billy" orders the spawning of turtle "slave202" and needs it to be told to travel to a point in the world.
2. Turtle "slave202" is created, but only has a default program with no clue who it is, where it came from, and what it needs to do.
3. slave202 somehow reaches out blindly to a server to grab its instructions and at the same time send up its personal info, like ID.
My thought was to have a "briefer" computer, which takes in turtle instructions from master computers, and info requests from dumb new turtles, and then makes the connection. Perhaps the Briefer would connect new requests with existing instructions via GPS location, I'm not sure.
Sorry for the late response.
As I side note, your (Lupus) Hive program seems pretty close to my end goal with this project. If I get fluent enough in lua, I just might ask to help.
7083 posts
Location
Tasmania (AU)
Posted 11 November 2016 - 04:24 AM
FWIW, I wrote a setup along such lines. My problem involved wood-chopping turtles above my base being randomly destroyed when trees grew (an issue which only applies with certain trees from mods).
I had
a computer which periodically sent out rednet pings to each turtle, and if one stopped responding over a prolonged period, it assumed it was lost.
A crafting turtle was then messaged with the
label of the missing turtle - it gathered the components for a new wood chopper, wrote the label to an "id" file in a disk drive, and then placed the new turtle next to that drive before starting it.
The startup script in the disk drive had the new turtle program itself according to the label found in the ID file - basically each new chopper ended up running the exact same script, but with a different "node" file telling it which co-ordinates it should plant / harvest around.
The main server used a "turtles" table to keep tabs on details such as the last known ID number of each turtle, when they last responded, and so on. Whenever a turtle reported in, it updated the ID in the table accordingly.
This was written quite some time ago - since then
the protocol system has been added to ComputerCraft, which makes network identification even easier.
15 posts
Location
Microscopic Village in Nebraska.
Posted 15 November 2016 - 03:54 AM
Now, that's a much better idea. Why not just load instructions from a instruction file written to the turtle while spawning?
Certainly seems easier than broadcasting and figuring stuff out via Rednet.
Thanks.