92 posts
Posted 11 June 2012 - 08:45 PM
hello,
i am writing a startup program witch should execute a program mentioned in the file startupprogram.txt
but everey time i get "startup:9:attempt to index ? (a nil value)"
i know the file exist.
there is "chestdispencer" written into it.
it's pretty mutch annoying me,
does someone know the awnser?
this is my lastest version of it.
sorry for bad english, i'm from holland
Spoiler
term.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 not fs.exists("startupprogram.txt") then
fs.open("tartupprogram.txt", "r")
local sexecute = file.readAll()
file.close()
lounchstartuppr=true
else
print("opening on startup; -")
end
print("##################################################\n")
sleep(3)
if lounchstartuppr==true then
print("starting program")
sleep(1)
shell.run(execute)
end
term.clear()
term.setCursorPos(1, 1)
1604 posts
Posted 11 June 2012 - 09:01 PM
You have to save the file handle returned by fs.open to a variable to use it:
local file = fs.open("tartupprogram.txt", "r")
Also, change this line:
if not fs.exists("startupprogram.txt") then
to:
if fs.exists("startupprogram.txt") then
to check that the file exists.
92 posts
Posted 12 June 2012 - 12:49 PM
thanx you al lot, this forum is great,
in the first place MysticT, you are great.
in the second place, no whining people.
it is working and i can start my factory now a lot more efficient
92 posts
Posted 12 June 2012 - 05:06 PM
i tried to tackle the last bug, but couldn't get it, i am realy desparate.
this is my startupprogram:
Spoiler
term.clear()
print("nnn##################################################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)
print(whattodo)
sleep(4)
shell.run(whattodo)
else
term.clear()
term.setCursorPos(1, 1)
end
and my startupprogram.txt contains this
Spoiler
"receivemessage"
and it is not in my program called receivemessage, but here is the code
Spoiler
print("starting program receive message")
rednet.open("left")
sleep(0.5)
print("waiting for message")
sender, whattodo = rednet.receive()
print("message received from computer ", id)
print("message was; ",whattodo)
print("confirming message")
rednet.send(sender, "confirmed")
print("whattodo")
shell.run(whattodo)
1604 posts
Posted 12 June 2012 - 07:10 PM
Do you get an error?
The problem might be that you receive some message that's not a program name, so it can't run it.
92 posts
Posted 13 June 2012 - 12:21 PM
i know sure it's te right programname, i used three different names with and without ".
i also changed value's and tried things from the internet.
but i still get a shell.run error that he can't index a nil value.
but if i print it, i get the programname.
i realy do'nt have any clue anymore.
18 posts
Posted 13 June 2012 - 01:24 PM
First of all, get those quotes(") away in the file, because when you read the file, it will automaticly return it as a string.
Secondly, make sure that the file you want to start is in the same folder as the startup file!
30 posts
Posted 13 June 2012 - 01:26 PM
Is the error the exact same with this error, as the one supplied in your original post? If not please supply the newest error message.
Cause, if it's the exact same, and your posting of the code is correct, then it would try to open the file, but then errors on reading it.
So easy way to test this, is to add in a check after opening the file like so:
if not file then print("unable to open startupprogram.txt")
else
(rest of your code here)
end
if you then get the error that it was unable to open, and your sure the file does exist, I would probably assume Maarten is correst and it's a pathing issue.
92 posts
Posted 13 June 2012 - 07:05 PM
i'm going to open this in a new topic.
(3 topic's about one program…)