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

[Lua] [Error] Custom Startup Not Loading Shell API

Started by KillaVanilla, 30 August 2012 - 09:40 PM
KillaVanilla #1
Posted 30 August 2012 - 11:40 PM
I'm trying to make a custom network-loading script that runs on startup. the only problem with this, though, is that it can't use the shell API's functions. This also happens with any programs run by the downloaded shell.

From what I've seen of the code, this shouldn't happen, as the shell program itself loads the shell API, and then runs the startup program.

Below is the code:

-- Network Boot System
local timeout = 10
local side = "top"
rednet.open(side)
function advancedOptions()
print("Select a boot file:")
bootID = io.read()
return bootID
end
function doBoot()
local bootFile = "default"
term.clear()
term.setCursorPos(1,1)
print("NETWORK BOOT CLIENT")
print("Press any key within 5 seconds to select a boot file.")
os.startTimer(5)
while true do
  event = os.pullEvent()
  if event == "timer" then
   print("Boot file not selected. Going to default...")
   break
  end
  if event == "key" then
   bootFile = advancedOptions()
   break
  end
end
rednet.broadcast("boot:"..bootFile)
bootServer, bootshell, distance = rednet.receive(timeout)
if bootshell == nil then
  print("ERROR: Could not contact boot server!")
  shell.exit()
end
print("Boot server contacted. Boot Server ID:"..bootServer)
shell = fs.open("shell", "w")
shell.write(bootshell)
shell.close()
print("Boot file downloaded! Running shell...")
os.sleep(2)
term.clear()
term.setCursorPos(1,1)
shell.setPath("/")
rednet.close(side)
os.sleep(2)
os.run({},"shell")
end
doBoot()
MysticT #2
Posted 30 August 2012 - 11:49 PM
You overwrite the shell api in this line:

shell = fs.open("shell", "w")
Change the variable name and it should work.
KillaVanilla #3
Posted 30 August 2012 - 11:57 PM
Thank you!