local ACTIONS= { ["exit"] = endProgram, ["addturtle"] = addTurtle, ["removeturtle"] = removeTurtle, ["listturtles"] = listTurtles } function endProgram() shell.exit() end function addTurtle() print("Turtle ID: ") term.setCursorPos(12,4) id = read() local h = fs.open("TurtleIDList", fs.exists("TurtleIDList") and "a" or "w") h.writeLine(id) h.close() end function removeTurtle() if(not fs.exists("TurtleIDList")) then print("No Turtle ID's Saved") sleep(3) return end print("Turtle ID: ") term.setCursorPos(12,4) id = read() local currentTurtles = fs.open("TurtleIDList", "r") local ids = {} while true do currentId = currentTurtles.readLine() if(currentId == nil) then print("End Of IDS") break end if(currentId == id) then print("ID Removed") sleep(3) else ids[#ids + 1] = currentId end end currentTurtles.close() local newTurtles = fs.open("TurtleIDList", "w") for i, writeID in ipairs(ids) do newTurtles.writeLine(writeID) end newTurtles.close() end function listTurtles() if(not fs.exists("TurtleIDList")) then print("No Turtle ID's Saved") sleep(3) return end local currentTurtles = fs.open("TurtleIDList", "r") local ids = {} while true do currentId = currentTurtles.readLine() if(currentId == nil) then break end ids[#ids + 1] = currentId end currentTurtles.close() for i, writeID in ipairs(ids) do print(writeID) sleep(1) end sleep(3) end while true do term.clear() term.setCursorPos(1,1) print("SkyNet Dispatch") term.setCursorPos(1,3) print("Action: ") term.setCursorPos(8,3) local action = string.lower(read()) action = action:gsub("%s+", "") local func = ACTIONS[action] if(func) then func() else print("Action '"..action.."' Not Found") sleep(3) end end
What happens after the computer turns on, is no matter what I type in for an action, it automatically says Actions not found even if it is a valid action. If I Ctrl+T out of the program and run it from terminal again, it works as designed. Until the user restarts the computer, of course. Thanks for your help in advance.