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
Setting a computer's ID
Started by maxmacher, Mar 24 2013 03:33 PM
6 replies to this topic
#1
Posted 24 March 2013 - 03:33 PM
#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.
#3
Posted 24 March 2013 - 03:37 PM
And if its a turtle, setting the label will have it keep its fuel level too.
#4
Posted 14 April 2013 - 04: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?
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?
#5
Posted 14 April 2013 - 05: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:
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
#6
Posted 21 April 2013 - 01:22 AM
Yes, I think that could be a good strategy. Something like, in pseudocode:
Master:
NamedSend(Name, Message),
On Slave side startup code contains:
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)
#7
Posted 21 April 2013 - 06:29 AM
Actually, I just realized I'm being stupid. The database is already there: ..\labels.txt or something similar.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











