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

Setting a computer's ID

Started by maxmacher, 24 March 2013 - 02:33 PM
maxmacher #1
Posted 24 March 2013 - 03:33 PM
Is there any way to set the ID, and therefore the path to the lua code, of a computer or turtle? I'd like to pick up and move a computer, and set it down somewhere else without changing the old ID.
Thanks
Cloudy #2
Posted 24 March 2013 - 03:35 PM
No. But you can set a label on the computer/turtle - you can then move it and all data will stay.
theoriginalbit #3
Posted 24 March 2013 - 03:37 PM
And if its a turtle, setting the label will have it keep its fuel level too. :)/>
maxmacher #4
Posted 14 April 2013 - 05:26 AM
Thanks, I think this will let me do what I need to. What would really be great is to be able to let a master computer communicate with slave turtles by label.
I suppose I could set each slave to broadcast its name and ID (now that they are nailed down, thank you), The master could listen and record a database of names and set a communication channel for each.

Anybody have a better idea or code for this?
Engineer #5
Posted 14 April 2013 - 06:03 AM
You should use: os.getComputerLabel()
That will return the current computer label, if there is none, it will return nil.

For your database you would want to set up some kind of table:

local slaves = {
  ["A computer label"] = somevalue,
  ["Another computer label"] = some other value
}

-- Or, if you only want to check if your database contains that label:
local slaves = {
  ["slave label"] = true,
  ["another slave"] = true
}

local id, label = rednet.receive()
if slaves[label] then
   -- execute the code for that
end
maxmacher #6
Posted 21 April 2013 - 02:22 AM
Yes, I think that could be a good strategy. Something like, in pseudocode:

Master:

Rednet.Broadcast("Identify")
Receive replies [ID, Name]
Build database on Name.

NamedSend(Name, Message),

On Slave side startup code contains:
messageLoop
	local ID, message, distance = rednet.receive()
	if message = "Identify"
		rednet.send(ID, MyName)
maxmacher #7
Posted 21 April 2013 - 07:29 AM
Actually, I just realized I'm being stupid. The database is already there: ..\labels.txt or something similar.