This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LNETeam's profile picture

Auto Installation Help

Started by LNETeam, 24 July 2012 - 07:48 PM
LNETeam #1
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()
jay5476 #2
Posted 24 July 2012 - 10:55 PM
try this
print("Enter Name of directory You Wish to install")
file = read()
fs.run("cp, <program you wish to install> "..file)
print("done")
LNETeam #3
Posted 24 July 2012 - 11:36 PM
I found what was wrong but with the same code only fixed a new problem arises… attempt to index? (a nil value)

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)
return x
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 Technologies")
 
  local sEvent, nKey = os.pullEvent("key")
 
  if nKey == 200 then
   if tChoices[nSelection - 1] then
    nSelection = nSelection - 1
   end
  elseif nKey == 208 then
   if tChoices[nSelection + 1] then
    nSelection = nSelection + 1
   end
  elseif nKey == 28 then
   if tChoices[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 Installation")
    local y = getCenterY()
    term.setCursorPos(x, y)
    term.write("Cancelling Installation")
    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, "Select software package:")
   mActions[nSelection]()
  elseif nMenuNum == 1 then
   mChoices = {}
   mActions = {}
   mChoices[0] = "LNEX Security System" .. sLNETOSVersionClient
   mChoices[1] = "Return"
   mActions[0] = function() nMenuNum = 2 sVersion = "Client" end
   mActions[1] = function() nMenuNum = 0 end
   local nSelection = runMenu(mChoices, "Select a LNEX 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 = getCenterX("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--
mDirs = {}
mDir[1] = "/LNEX/baseNet"
mDir[2] = "/LNEX/secpref"
mDir[3] = "/LNEX/data"
mDir[4] = "/LNEX/data/retrieve"
mDir[5] = "/LNEX/APIS"
print("Creating Directories")
print()
for n = 1, #tDirs do
if not fs.isDir(mDirs[n]) then fs.makeDir(mDirs[n]) end
term.setCursorPos(1, 5)
term.clearLine()
term.write(mDirs[n])
fs.makeDir(mDirs[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)
mAPIs = {}
mAPIs[1] = "WFCI"
mAPIs[2] = "WPCI"
mAPIs[3] = "WAPI"
mAPIs[4] = "WNIL"
for n = 1, #mAPIs do
term.setCursorPos(1, 5)
term.clearLine()
term.write("/LNEX/APIS/" .. mAPIs[n])
if fs.exists("/LNEX/APIS/" .. mAPIs[n]) then fs.delete("/LNEX/APIS/" .. mAPIs[n]) end
fs.copy("/disk/CORE/APIS/" .. mAPIs[n], "/LNEX/APIS/" .. mAPIs[n])
sleep(0.1)
end
os.loadAPI("/LNEX/APIS/WFCI")
mFiles = {}
mFiles[1] = "/Client/LNEX"
for n = 1, #mFiles do
if n > 5 then _sPath = sCopyPath .. mFiles[n] else _sPath = "/disk/CORE" .. mFiles[n] end
sPath = "/LNEX/baseNet" .. mFiles[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 = getCenterX("Finishing Installation")
local y = getCenterY()
term.setCursorPos(x, y)
term.write("Finishing Installation")
local x = getCenterX("Please wait...")
term.setCursorPos(x, y + 1)
term.write("Please wait...")
sleep(3)
term.setCursorPos(1, 1)
term.clear()
os.reboot()