Jump to content




Setting a computer's ID


  • You cannot reply to this topic
6 replies to this topic

#1 maxmacher

  • Members
  • 4 posts

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

#2 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

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 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 24 March 2013 - 03:37 PM

And if its a turtle, setting the label will have it keep its fuel level too. :)

#4 maxmacher

  • Members
  • 4 posts

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?

#5 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

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:
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 maxmacher

  • Members
  • 4 posts

Posted 21 April 2013 - 01: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)


#7 maxmacher

  • Members
  • 4 posts

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users