Fixed LUA scripts crash with invalid data file
Added example to initial help message Added help message on termination Added explicit limits on negative movement
This commit is contained in:
parent
0876802a9e
commit
aab3a05d6f
7 changed files with 73 additions and 37 deletions
|
@ -426,6 +426,7 @@ function data_read()
|
|||
local file = fs.open("shipdata.txt", "r")
|
||||
data = textutils.unserialize(file.readAll())
|
||||
file.close()
|
||||
if data == nil then data = {}; end
|
||||
end
|
||||
if data.reactor_mode == nil then data.reactor_mode = 0; end
|
||||
if data.reactor_rate == nil then data.reactor_rate = 100; end
|
||||
|
@ -874,6 +875,7 @@ function connections_page()
|
|||
WriteLn("")
|
||||
SetColorTitle()
|
||||
WriteLn("Please refer to below menu for keyboard controls")
|
||||
WriteLn("For example, press 1 to access Reactor page")
|
||||
end
|
||||
|
||||
-- peripheral boot up
|
||||
|
@ -946,4 +948,5 @@ if monitors ~= nil then
|
|||
end
|
||||
end
|
||||
SetCursorPos(1, 1)
|
||||
Write("")
|
||||
WriteLn("Program terminated")
|
||||
WriteLn("Type startup to restart it")
|
||||
|
|
|
@ -703,6 +703,7 @@ function data_read()
|
|||
local file = fs.open("shipdata.txt", "r")
|
||||
data = textutils.unserialize(file.readAll())
|
||||
file.close()
|
||||
if data == nil then data = {}; end
|
||||
end
|
||||
if data.core_summon == nil then data.core_summon = false; end
|
||||
if data.reactor_mode == nil then data.reactor_mode = 0; end
|
||||
|
@ -902,28 +903,33 @@ function core_page_setMovement()
|
|||
SetColorDefault()
|
||||
SetCursorPos(1, 3)
|
||||
|
||||
core_movement[1] = core_page_setDistanceAxis(2, "Front", core_movement[1], math.abs(core_front + core_back + 1))
|
||||
core_movement[2] = core_page_setDistanceAxis(3, "Up" , core_movement[2], math.abs(core_up + core_down + 1))
|
||||
core_movement[3] = core_page_setDistanceAxis(4, "Right", core_movement[3], math.abs(core_left + core_right + 1))
|
||||
core_movement[1] = core_page_setDistanceAxis(2, "Forward" , "Front", "Back", core_movement[1], math.abs(core_front + core_back + 1))
|
||||
core_movement[2] = core_page_setDistanceAxis(3, "Vertical", "Up" , "Down", core_movement[2], math.abs(core_up + core_down + 1))
|
||||
core_movement[3] = core_page_setDistanceAxis(4, "Lateral" , "Right", "Left", core_movement[3], math.abs(core_left + core_right + 1))
|
||||
core_movement = { ship.movement(core_movement[1], core_movement[2], core_movement[3]) }
|
||||
end
|
||||
|
||||
function core_page_setDistanceAxis(line, axis, userEntry, shipLength)
|
||||
function core_page_setDistanceAxis(line, axis, positive, negative, userEntry, shipLength)
|
||||
local maximumDistance = shipLength + 127
|
||||
if core_isInHyper and line ~= 3 then
|
||||
maximumDistance = shipLength + 127 * 100
|
||||
end
|
||||
SetCursorPos(1, line + 1)
|
||||
Write(positive .. " is " .. ( shipLength + 1) .. ", maximum is " .. maximumDistance .. " ")
|
||||
SetCursorPos(1, line + 2)
|
||||
Write(negative .. " is " .. (-shipLength - 1) .. ", maximum is " .. -maximumDistance .. " ")
|
||||
repeat
|
||||
SetCursorPos(1, line)
|
||||
Write(axis .. " (min " .. (shipLength + 1) .. ", max " .. maximumDistance .. "): ")
|
||||
Write(axis .. " movement: ")
|
||||
userEntry = readInputNumber(userEntry)
|
||||
if userEntry == 0 then
|
||||
return userEntry
|
||||
end
|
||||
if math.abs(userEntry) <= shipLength or math.abs(userEntry) > maximumDistance then
|
||||
if userEntry ~= 0 and (math.abs(userEntry) <= shipLength or math.abs(userEntry) > maximumDistance) then
|
||||
ShowWarning("Wrong distance. Try again.")
|
||||
end
|
||||
until math.abs(userEntry) > shipLength and math.abs(userEntry) <= maximumDistance
|
||||
until userEntry == 0 or (math.abs(userEntry) > shipLength and math.abs(userEntry) <= maximumDistance)
|
||||
SetCursorPos(1, line + 1)
|
||||
ClearLine()
|
||||
SetCursorPos(1, line + 2)
|
||||
ClearLine()
|
||||
|
||||
return userEntry
|
||||
end
|
||||
|
@ -2058,6 +2064,7 @@ function connections_page()
|
|||
WriteLn("")
|
||||
SetColorTitle()
|
||||
WriteLn("Please refer to below menu for keyboard controls")
|
||||
WriteLn("For example, press 1 to access Reactor page")
|
||||
end
|
||||
|
||||
-- peripheral boot up
|
||||
|
@ -2161,4 +2168,5 @@ if monitors ~= nil then
|
|||
end
|
||||
end
|
||||
SetCursorPos(1, 1)
|
||||
Write("")
|
||||
WriteLn("Program terminated")
|
||||
WriteLn("Type startup to restart it")
|
||||
|
|
|
@ -422,6 +422,7 @@ function data_read()
|
|||
local file = fs.open("shipdata.txt", "r")
|
||||
data = textutils.unserialize(file.readAll())
|
||||
file.close()
|
||||
if data == nil then data = {}; end
|
||||
end
|
||||
if data.core_summon == nil then data.core_summon = false; end
|
||||
end
|
||||
|
@ -609,28 +610,33 @@ function core_page_setMovement()
|
|||
SetColorDefault()
|
||||
SetCursorPos(1, 3)
|
||||
|
||||
core_movement[1] = core_page_setDistanceAxis(2, "Front", core_movement[1], math.abs(core_front + core_back + 1))
|
||||
core_movement[2] = core_page_setDistanceAxis(3, "Up" , core_movement[2], math.abs(core_up + core_down + 1))
|
||||
core_movement[3] = core_page_setDistanceAxis(4, "Right", core_movement[3], math.abs(core_left + core_right + 1))
|
||||
core_movement[1] = core_page_setDistanceAxis(2, "Forward" , "Front", "Back", core_movement[1], math.abs(core_front + core_back + 1))
|
||||
core_movement[2] = core_page_setDistanceAxis(3, "Vertical", "Up" , "Down", core_movement[2], math.abs(core_up + core_down + 1))
|
||||
core_movement[3] = core_page_setDistanceAxis(4, "Lateral" , "Right", "Left", core_movement[3], math.abs(core_left + core_right + 1))
|
||||
core_movement = { ship.movement(core_movement[1], core_movement[2], core_movement[3]) }
|
||||
end
|
||||
|
||||
function core_page_setDistanceAxis(line, axis, userEntry, shipLength)
|
||||
function core_page_setDistanceAxis(line, axis, positive, negative, userEntry, shipLength)
|
||||
local maximumDistance = shipLength + 127
|
||||
if core_isInHyper and line ~= 3 then
|
||||
maximumDistance = shipLength + 127 * 100
|
||||
end
|
||||
SetCursorPos(1, line + 1)
|
||||
Write(positive .. " is " .. ( shipLength + 1) .. ", maximum is " .. maximumDistance .. " ")
|
||||
SetCursorPos(1, line + 2)
|
||||
Write(negative .. " is " .. (-shipLength - 1) .. ", maximum is " .. -maximumDistance .. " ")
|
||||
repeat
|
||||
SetCursorPos(1, line)
|
||||
Write(axis .. " (min " .. (shipLength + 1) .. ", max " .. maximumDistance .. "): ")
|
||||
Write(axis .. " movement: ")
|
||||
userEntry = readInputNumber(userEntry)
|
||||
if userEntry == 0 then
|
||||
return userEntry
|
||||
end
|
||||
if math.abs(userEntry) <= shipLength or math.abs(userEntry) > maximumDistance then
|
||||
if userEntry ~= 0 and (math.abs(userEntry) <= shipLength or math.abs(userEntry) > maximumDistance) then
|
||||
ShowWarning("Wrong distance. Try again.")
|
||||
end
|
||||
until math.abs(userEntry) > shipLength and math.abs(userEntry) <= maximumDistance
|
||||
until userEntry == 0 or (math.abs(userEntry) > shipLength and math.abs(userEntry) <= maximumDistance)
|
||||
SetCursorPos(1, line + 1)
|
||||
ClearLine()
|
||||
SetCursorPos(1, line + 2)
|
||||
ClearLine()
|
||||
|
||||
return userEntry
|
||||
end
|
||||
|
@ -900,6 +906,7 @@ function connections_page()
|
|||
WriteLn("")
|
||||
SetColorTitle()
|
||||
WriteLn("Please refer to below menu for keyboard controls")
|
||||
WriteLn("For example, press 1 to access Ship core page")
|
||||
end
|
||||
|
||||
-- peripheral boot up
|
||||
|
@ -982,4 +989,5 @@ if monitors ~= nil then
|
|||
end
|
||||
end
|
||||
SetCursorPos(1, 1)
|
||||
Write("")
|
||||
WriteLn("Program terminated")
|
||||
WriteLn("Type startup to restart it")
|
||||
|
|
|
@ -444,6 +444,7 @@ function data_read()
|
|||
local file = fs.open("shipdata.txt", "r")
|
||||
data = textutils.unserialize(file.readAll())
|
||||
file.close()
|
||||
if data == nil then data = {}; end
|
||||
end
|
||||
if data.laser_batteries == nil then data.laser_batteries = {}; end
|
||||
laser_batteries = data.laser_batteries
|
||||
|
@ -1329,6 +1330,7 @@ function connections_page()
|
|||
WriteLn("")
|
||||
SetColorTitle()
|
||||
WriteLn("Please refer to below menu for keyboard controls")
|
||||
WriteLn("For example, press 1 to access Laser batteries page")
|
||||
end
|
||||
|
||||
-- peripheral boot up
|
||||
|
@ -1405,4 +1407,5 @@ if monitors ~= nil then
|
|||
end
|
||||
end
|
||||
SetCursorPos(1, 1)
|
||||
Write("")
|
||||
WriteLn("Program terminated")
|
||||
WriteLn("Type startup to restart it")
|
||||
|
|
|
@ -378,6 +378,7 @@ function data_read()
|
|||
data = serialization.unserialize(rawData)
|
||||
end
|
||||
file:close()
|
||||
if data == nil then data = {}; end
|
||||
end
|
||||
if data.reactor_mode == nil then data.reactor_mode = 0; end
|
||||
if data.reactor_rate == nil then data.reactor_rate = 100; end
|
||||
|
@ -814,6 +815,7 @@ function connections_page()
|
|||
WriteLn("")
|
||||
SetColorTitle()
|
||||
WriteLn("Please refer to below menu for keyboard controls")
|
||||
WriteLn("For example, press 1 to access Reactor page")
|
||||
end
|
||||
|
||||
-- peripheral boot up
|
||||
|
@ -881,4 +883,5 @@ until abort
|
|||
SetMonitorColorFrontBack(0xFFFFFF, 0x000000)
|
||||
term.clear()
|
||||
SetCursorPos(1, 1)
|
||||
Write("")
|
||||
WriteLn("Program terminated")
|
||||
WriteLn("Type reboot to restart it")
|
||||
|
|
|
@ -374,6 +374,7 @@ function data_read()
|
|||
data = serialization.unserialize(rawData)
|
||||
end
|
||||
file:close()
|
||||
if data == nil then data = {}; end
|
||||
end
|
||||
if data.core_summon == nil then data.core_summon = false; end
|
||||
end
|
||||
|
@ -562,28 +563,33 @@ function core_page_setMovement()
|
|||
SetColorDefault()
|
||||
SetCursorPos(1, 3)
|
||||
|
||||
core_movement[1] = core_page_setDistanceAxis(2, "Front", core_movement[1], math.abs(core_front + core_back + 1))
|
||||
core_movement[2] = core_page_setDistanceAxis(3, "Up" , core_movement[2], math.abs(core_up + core_down + 1))
|
||||
core_movement[3] = core_page_setDistanceAxis(4, "Right", core_movement[3], math.abs(core_left + core_right + 1))
|
||||
core_movement[1] = core_page_setDistanceAxis(2, "Forward" , "Front", "Back", core_movement[1], math.abs(core_front + core_back + 1))
|
||||
core_movement[2] = core_page_setDistanceAxis(3, "Vertical", "Up" , "Down", core_movement[2], math.abs(core_up + core_down + 1))
|
||||
core_movement[3] = core_page_setDistanceAxis(4, "Lateral" , "Right", "Left", core_movement[3], math.abs(core_left + core_right + 1))
|
||||
core_movement = { ship.movement(core_movement[1], core_movement[2], core_movement[3]) }
|
||||
end
|
||||
|
||||
function core_page_setDistanceAxis(line, axis, userEntry, shipLength)
|
||||
function core_page_setDistanceAxis(line, axis, positive, negative, userEntry, shipLength)
|
||||
local maximumDistance = shipLength + 127
|
||||
if core_isInHyper and line ~= 3 then
|
||||
maximumDistance = shipLength + 127 * 100
|
||||
end
|
||||
SetCursorPos(1, line + 1)
|
||||
Write(positive .. " is " .. ( shipLength + 1) .. ", maximum is " .. maximumDistance .. " ")
|
||||
SetCursorPos(1, line + 2)
|
||||
Write(negative .. " is " .. (-shipLength - 1) .. ", maximum is " .. -maximumDistance .. " ")
|
||||
repeat
|
||||
SetCursorPos(1, line)
|
||||
Write(axis .. " (min " .. (shipLength + 1) .. ", max " .. maximumDistance .. "): ")
|
||||
Write(axis .. " movement: ")
|
||||
userEntry = readInputNumber(userEntry)
|
||||
if userEntry == 0 then
|
||||
return userEntry
|
||||
end
|
||||
if math.abs(userEntry) <= shipLength or math.abs(userEntry) > maximumDistance then
|
||||
if userEntry ~= 0 and (math.abs(userEntry) <= shipLength or math.abs(userEntry) > maximumDistance) then
|
||||
ShowWarning("Wrong distance. Try again.")
|
||||
end
|
||||
until math.abs(userEntry) > shipLength and math.abs(userEntry) <= maximumDistance
|
||||
until userEntry == 0 or (math.abs(userEntry) > shipLength and math.abs(userEntry) <= maximumDistance)
|
||||
SetCursorPos(1, line + 1)
|
||||
ClearLine()
|
||||
SetCursorPos(1, line + 2)
|
||||
ClearLine()
|
||||
|
||||
return userEntry
|
||||
end
|
||||
|
@ -847,6 +853,7 @@ function connections_page()
|
|||
WriteLn("")
|
||||
SetColorTitle()
|
||||
WriteLn("Please refer to below menu for keyboard controls")
|
||||
WriteLn("For example, press 1 to access Ship core page")
|
||||
end
|
||||
|
||||
-- peripheral boot up
|
||||
|
@ -924,4 +931,5 @@ end
|
|||
SetMonitorColorFrontBack(0xFFFFFF, 0x000000)
|
||||
term.clear()
|
||||
SetCursorPos(1, 1)
|
||||
Write("")
|
||||
WriteLn("Program terminated")
|
||||
WriteLn("Type reboot to restart it")
|
||||
|
|
|
@ -396,6 +396,7 @@ function data_read()
|
|||
data = serialization.unserialize(rawData)
|
||||
end
|
||||
file:close()
|
||||
if data == nil then data = {}; end
|
||||
end
|
||||
if data.laser_batteries == nil then data.laser_batteries = {}; end
|
||||
laser_batteries = data.laser_batteries
|
||||
|
@ -1259,6 +1260,7 @@ function connections_page()
|
|||
WriteLn("")
|
||||
SetColorTitle()
|
||||
WriteLn("Please refer to below menu for keyboard controls")
|
||||
WriteLn("For example, press 1 to access Laser batteries page")
|
||||
end
|
||||
|
||||
-- peripheral boot up
|
||||
|
@ -1330,4 +1332,5 @@ until abort
|
|||
SetMonitorColorFrontBack(0xFFFFFF, 0x000000)
|
||||
term.clear()
|
||||
SetCursorPos(1, 1)
|
||||
Write("")
|
||||
WriteLn("Program terminated")
|
||||
WriteLn("Type reboot to restart it")
|
||||
|
|
Loading…
Reference in a new issue