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

shell.run() problem,

Started by blipman17, 13 June 2012 - 05:16 PM
blipman17 #1
Posted 13 June 2012 - 07:16 PM
hello,
i've got a startupprogram that should work, but i don't get it working.
the error is a nil value error (think evereybody know wat it is) but i don't have any clue's any more.
my startupprogram search to a file called startupprogram.txt,
if it finds it, it shows the programname and after a few seconds it runs it.
at least it should run it.
it says that he can't index a nil value.
but i don't see any value that doesn't exist.

this is my startupprogram.

Spoilerterm.clear()
print("\n\n\n##################################################\n")
print("computercraft version; ", os.version())
print("Computer ID; ", os.computerID())
print("This computer is called; ", os.getComputerLabel())
lounchstartuppr=false
if fs.exists("startupprogram.txt") then
local file = fs.open("startupprogram.txt", "r")
whattodo = file.readAll()
file.close()
if whattodo ~= nil then
lounchstartuppr=true
print("opening on startup; ", whattodo)
else
print("file startupprogram.txt is not made proper")
end
else
print("opening on startup; -")
end
print("##################################################\n")
sleep(3)
print("going to execute")
if lounchstartuppr==true then
print("starting program")
sleep(1)
term.clear()
term.setCursorPos(1, 1)
shell.run(whattodo)
else
term.clear()
term.setCursorPos(1, 1)
end

and this is my startupprogram.txt
it's not mutch, i know.

Spoilerchestdispencer

the file startupprogram.txt is in the lua\rom\apis map.
and it is really not about my program chestdispencer.
and when i print whattodo just before shell.run(whattodo), it prints chestdispencer.

does anyone have a clue?
Lyqyd #2
Posted 13 June 2012 - 08:04 PM
So you're trying to tell it to run the name of the program, rather than running the program? Why the extra steps? Why not just put shell.run("chestdispenser") in your startup?

Also, stop starting new topics about the same problem.
MysticT #3
Posted 13 June 2012 - 08:10 PM
fs.open won't search the file for you, you need to give it the full path. It can't open the file, so it returns nil, always check the file handle before using it:

local file = fs.open("path", "r")
if file then
  -- use the file (file.read, file.write, etc)
  file.close() -- don't forget this
else
  print("Error opening file")
end

Also,

So you're trying to tell it to run the name of the program, rather than running the program? Why the extra steps? Why not just put shell.run("chestdispenser") in your startup?

Also, stop starting new topics about the same problem.
that. Just save it as startup and it should work. And ask in the same topic instead of making a new one.

Edit: One more thing: don't save files on the apis folder if they are not apis, cause the os will try to load them.