Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- receiver_setup.lua
- local configFileName = "displays.txt"
- function saveConfig(config)
- local file = fs.open(configFileName, "w")
- file.write(textutils.serialize(config))
- file.close()
- print("Configuration saved.")
- end
- function loadConfig()
- if fs.exists(configFileName) then
- local file = fs.open(configFileName, "r")
- local config = textutils.unserialize(file.readAll())
- file.close()
- return config
- else
- return {displays = {}}
- end
- end
- local config = loadConfig()
- function drawMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("Displays Setup")
- print("Configured Displays:")
- for i, display in ipairs(config.displays) do
- print(i .. ". Side: " .. display.side .. ", Type: " .. display.type)
- end
- print("\n1. Add Display")
- print("2. Edit Display")
- print("3. Delete Display")
- print("4. Exit")
- print("5. Exit & Run")
- end
- function addDisplay()
- local display = {}
- print("Enter the side the display is connected to (left, right, top, bottom, front, back):")
- display.side = read()
- print("Do you want to display the floor number or name? (Enter 'number' or 'name'):")
- display.type = read()
- table.insert(config.displays, display)
- saveConfig(config)
- end
- function editDisplay()
- print("Enter the index of the display to edit:")
- local index = tonumber(read())
- if config.displays[index] then
- print("Enter new side (currently " .. config.displays[index].side .. "):")
- config.displays[index].side = read()
- print("Enter new type ('number' or 'name', currently " .. config.displays[index].type .. "):")
- config.displays[index].type = read()
- saveConfig(config)
- else
- print("Invalid index.")
- end
- end
- function deleteDisplay()
- print("Enter the index of the display to delete:")
- local index = tonumber(read())
- if index and index >= 1 and index <= #config.displays then
- table.remove(config.displays, index)
- saveConfig(config)
- else
- print("Invalid index.")
- end
- end
- function mainMenu()
- drawMenu()
- local choice = read()
- if choice == "1" then
- addDisplay()
- elseif choice == "2" then
- editDisplay()
- elseif choice == "3" then
- deleteDisplay()
- elseif choice == "4" then
- return false -- Exit the program
- elseif choice == "5" then
- shell.run('receiver')
- end
- return true
- end
- while mainMenu() do
- -- Loop back to the main menu after each action
- end
Add Comment
Please, Sign In to add comment