Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Computer name:
- name="PC"
- --modem side(turtle: always "right"):
- side="right"
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function save()
- doc=fs.open("data", "w") --doc = fs.open(filename, mode(w))
- doc.writeLine(name)
- doc.close()
- end
- function load()
- doc=fs.open("data", "r")
- if doc==nil then
- else
- name=doc.readLine()
- doc.close()
- end
- end
- function startup()
- clear()
- print("Opening connection...")
- rednet.open(side) --enable modem on the right side of the PC
- load()
- sleep(0.5)
- clear()
- ownid=os.getComputerID()
- end
- function configure()
- clear()
- x,y=term.getSize()
- for i=0,x-1 do
- write("-")
- end
- print("Enter the new name of this computer!")
- print("Default: 'PC'")
- print("Current: ".."'"..name.."'")
- name=read()
- print("Set to: "..name)
- sleep(0.5)
- clear()
- print("Saving data...")
- save()
- sleep(0.3)
- end
- function main()
- clear()
- print("Waiting for commands... Client-ID: "..ownid)
- id,message = rednet.receive() --wait until a mesage is received
- if message == "Ping" then
- rednet.send(id,name) --return value
- print("Got pinged right now!")
- sleep(2)
- else
- if message == "stop" then
- clear()
- print("Shutting down...")
- rednet.send(id,"Shutting down...") --return value
- rednet.close(side)
- error()
- else
- if message == "wheat" then
- clear()
- print("Starting program...")
- rednet.send(id,"Farming...") --return value
- shell.run("wheat", "farm")
- else
- if message=="configure" then
- rednet.send(id,"Started configuration!") --return value
- clear()
- configure()
- else
- if message=="replant" then
- clear()
- print("Starting program...")
- rednet.send(id,"Replanting...") --return value
- shell.run("wheat", "replant")
- end
- end
- end
- end
- end
- main()
- end
- startup()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement