Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Student device startup.lua
- local modem = peripheral.find("modem")
- if not modem then
- error("No modem found. Please attach a wireless modem.")
- end
- local function downloadStudentLua()
- modem.open(1)
- print("Requesting latest student.lua...")
- -- Send a request to the server for the latest student.lua
- modem.transmit(1, 1, {type = "request_update"})
- local timer = os.startTimer(5) -- 5-second timeout
- while true do
- local event, param1, param2, param3, message = os.pullEvent()
- if event == "modem_message" then
- if type(message) == "table" and message.type == "update" then
- local file = fs.open("student.lua", "w")
- file.write(message.content)
- file.close()
- print("student.lua updated successfully.")
- return true
- end
- elseif event == "timer" and param1 == timer then
- print("Timeout: Failed to receive student.lua")
- return false
- end
- end
- end
- if downloadStudentLua() then
- shell.run("student.lua")
- else
- print("Failed to update. Running existing student.lua if available.")
- if fs.exists("student.lua") then
- shell.run("student.lua")
- else
- error("No student.lua available. Please contact an administrator.")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment