Jump to content


mannybjh

Member Since 21 Sep 2015
Offline Last Active May 27 2019 02:34 AM
-----

Topics I've Started

Weird program error on reboot

25 May 2019 - 03:56 AM

I am currently trying to write a turtle dispatching system for my single player world (Minecraft 1.6.4), and I am experiencing a weird bug. The program works, but whenever I restart the computer using shutdown or reboot command, it doesn't work as designed.

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.