Posted 24 July 2012 - 09:48 PM
Hi! Iv'e been working on a piece of software for an auto install program through disks.
I run the code as a startup from disk on reboot and I get the error "startup:126: bad argument: int expected, got nil"
Here's my code:
function os.pullEvent()
local cEvent, p1, p2, p3, p4, p5 = os.pullEventRaw()
if cEvent == "terminate" then
end
return cEvent, p1, p2, p3, p4, p5
end
function getCenterX(sText)
local nWidth = term.getSize()
local x = math.floor(nWidth / 2) - math.floor(string.len(sText) / 2)
end
function getCenterY()
local nWidth, nHeight = term.getSize()
local y = math.floor(nHeight / 2)
return y
end
function getRight(sText)
local nWidth = term.getSize()
local x = nWidth - string.len(sText)
return x + 1
end
function runMenu(mChoices, sMenuTitle)
local nSelection = 0
local bLoop = true
while bLoop == true do
term.clear()
term.setCursorPos(1,1)
print(sMenuTitle)
print()
for nLine = 0, #mChoices do
local sLine = " "
if nSelection == nLine then
sLine = "> "
end
sLine = sLine .. mChoices[nline]
print(sline)
end
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technoligies")
local sEvent, nKey = os.pullEvent("key")
if nKey == 200 then
if mChoices[nSelection - 1] then
nSelection = nSelection - 1
end
elseif nKey == 208 then
if mChoices[nSelection + 1] then
nSelection = nSelection + 1
end
elseif nKey == 28 then
if mChoices[nSelection] then
bLoop = false
return nSelection
end
end
end
end
function menu()
repeat
if nMenuNum == 0 then
mChoices = {}
mActions = {}
mChoices[0] = "LNET Security Program"
mChoices[1] = "Cancel Setup"
mActions[0] = function() nMenuNum = 1 end
mActions[1] = function()
term.clear()
local x = getCenterX("Cancelling Setup")
local y = getCenterY()
term.setCursorPos(x, y)
term.write("Cancelling Setup")
local x = getCenterX("Please wait….")
term.setCursorPos(x, y + 1)
term.write("Please wait….")
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
sleep(3)
os.shutdown()
end
local nSelection = runMenu(mChoices, "LNET Technologies")
mActions[nSelection]()
elseif nMenuNum == 1 then
mChoices = {}
mActions = {}
mChoices[0] = "LNEX Security System"
mChoices[1] = "Return"
mActions[0] = function() nMenuNum = 2 sVersion = "Client" end
mActions[1] = function() nMenuNum = 0 end
local nSelection = runMenu(mChoices, "Choose your version")
mActions[nSelection]()
elseif nMenuNum == 2 then
mChoices = {}
mActions = {}
mChoices[0] = "Install"
mChoices[1] = "Skip"
mChoices[2] = "Return"
mActions[0] = function() bMenuLoop = false bLogPref = true end
mActions[1] = function() bMenuLoop = false bLogPref = false end
mActions[2] = function() nMenuNum = 1 end
end
until bMenuLoop == false
end
–LNEX Software–
term.clear()
local x = getCenterX("Initializing Installation")
local y = getCenterY()
term.setCursorPos(x, y)
print("Initializing Installation")
local x = getCentreX("Please wait…")
term.setCursorPos(x, y + 1)
print("Please wait…")
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
sleep(3)
bMenuLoop = true
nMenuNum = 0
mChoices = {}
mActions = {}
menu()
term.clear()
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
term.setCursorPos(1,1)
if sVersion == "Client" then
sVersionNum = "v1.0.1"
sCopyPath = "/disk/CORE"
print("Installing LNEX Client " .. sVersionNum .. "…")
end
print()
–Creating Directories–
tDirs = {}
tDir[1] = "/LNEX/baseNet"
tDir[2] = "/LNEX/secpref"
tDir[3] = "/LNEX/data"
tDir[4] = "/LNEX/data/retrieve"
tDir[5] = "/LNEX/APIS"
print("Creating Directories")
print()
for n = 1, #tDirs do
if not fs.isDir(tDirs[n]) then fs.makeDir(tDirs[n]) end
term.setCursorPos(1, 5)
term.clearLine()
term.write(tDirs[n])
fs.makeDir(tDirs[n])
sleep(0.1)
end
term.setCursorPos(1, 3)
term.clearLine()
print("Copying files…")
print()
term.setCursorPos(1, 5)
term.clearLine()
term.write("/startup")
if fs.exists ("/startup") then fs.delete("/startup") end
fs.copy ("/disk/CORE/start/startup" , "/startup")
sleep(0.1)
tAPIs = {}
tAPIs[1] = "WFCI"
tAPIs[2] = "WPCI"
tAPIs[3] = "WAPI"
tAPIs[4] = "WNIL"
for n = 1, #tAPIs do
term.setCursorPos(1, 5)
term.clearLine()
term.write("/LNEX/APIS/" .. tAPIs[n])
if fs.exists("/LNEX/APIS/" .. tAPIs[n]) then fs.delete("/LNEX/APIS/" .. tAPIs[n]) end
fs.copy("/disk/CORE/APIS/" .. tAPIs[n], "/LNEX/APIS/" .. tAPIs[n])
sleep(0.1)
end
os.loadAPI("/LNEX/APIS/WFCI")
tFiles = {}
tFiles[1] = "/Client/LNEX"
for n = 1, #tFiles do
if n > 5 then _sPath = sCopyPath .. tFiles[n] else _sPath = "/disk/CORE" .. tFiles[n] end
sPath = "/LNEX/baseNet" .. tFiles[n]
term.setCursorPos(1, 5)
term.clearLine()
term.write(sPath)
if WFCI.exists(sPath) then fs.delete(sPath) end
fs.copy(_sPath, sPath)
sleep(0.1)
end
–Optinal Software–
if bLogPref == true then
term.setCursorPos(1, 5)
term.clearLine()
term.write("/LNEX/secpref/secprefa")
if WFCI.exists("/LNEX/secpref/secprefa") then fs.delete("/LNEX/secpref/secprefa") end
fs.copy(sCopyPath .. "/SecPreface", "/LNEX/secpref/secprefa")
sleep(0.1)
else
if WFCI.exists("/LNEX/secpref/secprefa") then fs.delete("/LNEX/secpref/secprefa") end
end
–Finalizing–
term.clear()
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
term.setCursorPos(1, 1)
print(sVersion .. " " .. sVersionNum .. " installation complete.")
sleep(0.1)
print()
print("Press any key to continue…")
os.pullEvent("key")
term.clear()
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
term.setCursorPos(1, 1)
for nSide = 1, 6 do
if nSide == 1 then sSide = "top"
elseif nSide == 2 then sSide = "bottom"
elseif nSide == 3 then sSide = "front"
elseif nSide == 4 then sSide = "back"
elseif nSide == 5 then sSide = "left"
elseif nSide == 6 then sSide = "right" end
disk.eject(sSide)
end
local x = getCentreX("Finishing Installation")
local y = getCentreY()
term.setCursorPos(x, y)
term.write("Finishing Installation")
local x = getCentreX("Please wait…")
term.setCursorPos(x, y + 1)
term.write("Please wait…")
sleep(3)
term.setCursorPos(1, 1)
term.clear()
os.reboot()
I run the code as a startup from disk on reboot and I get the error "startup:126: bad argument: int expected, got nil"
Here's my code:
function os.pullEvent()
local cEvent, p1, p2, p3, p4, p5 = os.pullEventRaw()
if cEvent == "terminate" then
end
return cEvent, p1, p2, p3, p4, p5
end
function getCenterX(sText)
local nWidth = term.getSize()
local x = math.floor(nWidth / 2) - math.floor(string.len(sText) / 2)
end
function getCenterY()
local nWidth, nHeight = term.getSize()
local y = math.floor(nHeight / 2)
return y
end
function getRight(sText)
local nWidth = term.getSize()
local x = nWidth - string.len(sText)
return x + 1
end
function runMenu(mChoices, sMenuTitle)
local nSelection = 0
local bLoop = true
while bLoop == true do
term.clear()
term.setCursorPos(1,1)
print(sMenuTitle)
print()
for nLine = 0, #mChoices do
local sLine = " "
if nSelection == nLine then
sLine = "> "
end
sLine = sLine .. mChoices[nline]
print(sline)
end
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technoligies")
local sEvent, nKey = os.pullEvent("key")
if nKey == 200 then
if mChoices[nSelection - 1] then
nSelection = nSelection - 1
end
elseif nKey == 208 then
if mChoices[nSelection + 1] then
nSelection = nSelection + 1
end
elseif nKey == 28 then
if mChoices[nSelection] then
bLoop = false
return nSelection
end
end
end
end
function menu()
repeat
if nMenuNum == 0 then
mChoices = {}
mActions = {}
mChoices[0] = "LNET Security Program"
mChoices[1] = "Cancel Setup"
mActions[0] = function() nMenuNum = 1 end
mActions[1] = function()
term.clear()
local x = getCenterX("Cancelling Setup")
local y = getCenterY()
term.setCursorPos(x, y)
term.write("Cancelling Setup")
local x = getCenterX("Please wait….")
term.setCursorPos(x, y + 1)
term.write("Please wait….")
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
sleep(3)
os.shutdown()
end
local nSelection = runMenu(mChoices, "LNET Technologies")
mActions[nSelection]()
elseif nMenuNum == 1 then
mChoices = {}
mActions = {}
mChoices[0] = "LNEX Security System"
mChoices[1] = "Return"
mActions[0] = function() nMenuNum = 2 sVersion = "Client" end
mActions[1] = function() nMenuNum = 0 end
local nSelection = runMenu(mChoices, "Choose your version")
mActions[nSelection]()
elseif nMenuNum == 2 then
mChoices = {}
mActions = {}
mChoices[0] = "Install"
mChoices[1] = "Skip"
mChoices[2] = "Return"
mActions[0] = function() bMenuLoop = false bLogPref = true end
mActions[1] = function() bMenuLoop = false bLogPref = false end
mActions[2] = function() nMenuNum = 1 end
end
until bMenuLoop == false
end
–LNEX Software–
term.clear()
local x = getCenterX("Initializing Installation")
local y = getCenterY()
term.setCursorPos(x, y)
print("Initializing Installation")
local x = getCentreX("Please wait…")
term.setCursorPos(x, y + 1)
print("Please wait…")
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
sleep(3)
bMenuLoop = true
nMenuNum = 0
mChoices = {}
mActions = {}
menu()
term.clear()
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
term.setCursorPos(1,1)
if sVersion == "Client" then
sVersionNum = "v1.0.1"
sCopyPath = "/disk/CORE"
print("Installing LNEX Client " .. sVersionNum .. "…")
end
print()
–Creating Directories–
tDirs = {}
tDir[1] = "/LNEX/baseNet"
tDir[2] = "/LNEX/secpref"
tDir[3] = "/LNEX/data"
tDir[4] = "/LNEX/data/retrieve"
tDir[5] = "/LNEX/APIS"
print("Creating Directories")
print()
for n = 1, #tDirs do
if not fs.isDir(tDirs[n]) then fs.makeDir(tDirs[n]) end
term.setCursorPos(1, 5)
term.clearLine()
term.write(tDirs[n])
fs.makeDir(tDirs[n])
sleep(0.1)
end
term.setCursorPos(1, 3)
term.clearLine()
print("Copying files…")
print()
term.setCursorPos(1, 5)
term.clearLine()
term.write("/startup")
if fs.exists ("/startup") then fs.delete("/startup") end
fs.copy ("/disk/CORE/start/startup" , "/startup")
sleep(0.1)
tAPIs = {}
tAPIs[1] = "WFCI"
tAPIs[2] = "WPCI"
tAPIs[3] = "WAPI"
tAPIs[4] = "WNIL"
for n = 1, #tAPIs do
term.setCursorPos(1, 5)
term.clearLine()
term.write("/LNEX/APIS/" .. tAPIs[n])
if fs.exists("/LNEX/APIS/" .. tAPIs[n]) then fs.delete("/LNEX/APIS/" .. tAPIs[n]) end
fs.copy("/disk/CORE/APIS/" .. tAPIs[n], "/LNEX/APIS/" .. tAPIs[n])
sleep(0.1)
end
os.loadAPI("/LNEX/APIS/WFCI")
tFiles = {}
tFiles[1] = "/Client/LNEX"
for n = 1, #tFiles do
if n > 5 then _sPath = sCopyPath .. tFiles[n] else _sPath = "/disk/CORE" .. tFiles[n] end
sPath = "/LNEX/baseNet" .. tFiles[n]
term.setCursorPos(1, 5)
term.clearLine()
term.write(sPath)
if WFCI.exists(sPath) then fs.delete(sPath) end
fs.copy(_sPath, sPath)
sleep(0.1)
end
–Optinal Software–
if bLogPref == true then
term.setCursorPos(1, 5)
term.clearLine()
term.write("/LNEX/secpref/secprefa")
if WFCI.exists("/LNEX/secpref/secprefa") then fs.delete("/LNEX/secpref/secprefa") end
fs.copy(sCopyPath .. "/SecPreface", "/LNEX/secpref/secprefa")
sleep(0.1)
else
if WFCI.exists("/LNEX/secpref/secprefa") then fs.delete("/LNEX/secpref/secprefa") end
end
–Finalizing–
term.clear()
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
term.setCursorPos(1, 1)
print(sVersion .. " " .. sVersionNum .. " installation complete.")
sleep(0.1)
print()
print("Press any key to continue…")
os.pullEvent("key")
term.clear()
local nWidth, nHeight = term.getSize()
local y = nHeight
local x = getRight("LNET Technologies")
term.setCursorPos(x, y)
term.write("LNET Technologies")
term.setCursorPos(1, 1)
for nSide = 1, 6 do
if nSide == 1 then sSide = "top"
elseif nSide == 2 then sSide = "bottom"
elseif nSide == 3 then sSide = "front"
elseif nSide == 4 then sSide = "back"
elseif nSide == 5 then sSide = "left"
elseif nSide == 6 then sSide = "right" end
disk.eject(sSide)
end
local x = getCentreX("Finishing Installation")
local y = getCentreY()
term.setCursorPos(x, y)
term.write("Finishing Installation")
local x = getCentreX("Please wait…")
term.setCursorPos(x, y + 1)
term.write("Please wait…")
sleep(3)
term.setCursorPos(1, 1)
term.clear()
os.reboot()