Hello,I was wondering how i can send from a turtle id to a master computer(just a example) without knowing the computer`s ID.That`s because i want to make a strip minner program that involves,more turtles that dig a 3X3 area each, so I don`t want to rewrite the ID in the program every time if i would go play on another server,or just make a new world.
And another thing that doesn`t bother me that much,but i would like to know how to do it.The thing I would like to know is :Session persistance.
I hope you can help me!
Thanks!
Alex
Sending Ids Between Turtles And Computers
Started by CyborgAlex, Jul 30 2013 12:11 PM
7 replies to this topic
#1
Posted 30 July 2013 - 12:11 PM
#2
Posted 30 July 2013 - 12:22 PM
local side = "back" --asuming the modem is on the back rednet.open(side) ID = os.computerID()--this function will return the computer ID rednet.broadcast(tostring(ID))
#3
Posted 30 July 2013 - 12:41 PM
Jappards, on 30 July 2013 - 12:22 PM, said:
local side = "back" --asuming the modem is on the back rednet.open(side) ID = os.computerID()--this function will return the computer ID rednet.broadcast(tostring(ID))
-- Opening modems
for _, side in pairs(rs.getSides()) do
if peripheral.getType(side) == "modem" then
rednet.open(side)
end
end
#4
Posted 30 July 2013 - 01:00 PM
Ok,that should do it.But assuming that the person that uses the program has limited programing knowledge,is it possible to make the program that doesn`t need any changes?
#5
Posted 30 July 2013 - 01:04 PM
CyborgAlex, on 30 July 2013 - 01:00 PM, said:
Ok,that should do it.But assuming that the person that uses the program has limited programing knowledge,is it possible to make the program that doesn`t need any changes?
Jappards, on 30 July 2013 - 12:22 PM, said:
local side = "back" --asuming the modem is on the back rednet.open(side) ID = os.computerID()--this function will return the computer ID rednet.broadcast(tostring(ID))
local side = "back"
rednet.open(side)
rednet.broadcast("PONG")
As when you receive a message you actually get the sender's id.
NOTE: I chose PONG because PING is used for the GPS system.
#6
Posted 30 July 2013 - 01:15 PM
But with Jappards`s method,how would the mastercomputer that the id is from the right turtles.
With your method for the MC,would be very simple
With your method for the MC,would be very simple
event, p1, p2 = os.pullEvent("rednet_message")
if p2 == "PONG" then
do something
end
#7
Posted 30 July 2013 - 01:24 PM
Turtle code:
Then the master computer would follow a similar structure to the above code, except the messages would be the reverse (waiting for the turtle message and sending a response, unless there is a save file with it's ID)
--# open the modems
for _, side in pairs(rs.getSides()) do
if peripheral.getType(side) == "modem" then
rednet.open(side)
end
end
--# the variable with the master computers id
local masterID
--# on first boot up (check this with a file, that you then create after this process)
if not fs.exists(".data") then
--# request a master computer
rednet.broadcast("Hey I want a master!")
--# wait for a response
local id, msg
repeat
id, msg = rednet.receive()
until msg == "I am your master!"
--# write that id out to file
local h = fs.open(".data","w")
h.write(id)
h.close()
masterID = id
else
--# we know the master, read it
local h = fs.open(".data","r")
masterID = tonumber(h.readLine())
h.close()
end
--# now just listen to only that computer and do what it says
Then the master computer would follow a similar structure to the above code, except the messages would be the reverse (waiting for the turtle message and sending a response, unless there is a save file with it's ID)
#8
Posted 30 July 2013 - 01:28 PM
OH thanks.You helped me a lot
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











