every time i run this script i keep getting
torch:21: attempt to index ? (a nil value)
please help
Posted 10 June 2012 - 11:26 AM
Posted 10 June 2012 - 11:52 AM
Posted 10 June 2012 - 12:52 PM
Posted 10 June 2012 - 05:04 PM
Posted 11 June 2012 - 07:09 PM
Posted 11 June 2012 - 07:25 PM
blipman17, on 11 June 2012 - 07:09 PM, said:
if fs.exists("startupprogram.txt")~="false" thenIt returns always true, because the boolean returned by the function will always be different from the string "false". So it tries to open the file, wich doesn't exist and returns nil.
if not fs.exists("startupprogram.txt") thenAnd you should always check the file handle returned by fs.open:
local file = fs.open("/path/to/file", "r") if file then -- use the file file.close() -- don't forget to close it else print("Error opening file") endAnd you probably want to change:
fs.open("/path/to/file", "r")to:
local file = fs.open("startupprogram.txt", "r")
Posted 11 June 2012 - 07:34 PM
MysticT, on 11 June 2012 - 07:25 PM, said:
blipman17, on 11 June 2012 - 07:09 PM, said:
if fs.exists("startupprogram.txt")~="false" thenIt returns always true, because the boolean returned by the function will always be different from the string "false". So it tries to open the file, wich doesn't exist and returns nil.
if not fs.exists("startupprogram.txt") thenAnd you should always check the file handle returned by fs.open:
local file = fs.open("/path/to/file", "r") if file then -- use the file file.close() -- don't forget to close it else print("Error opening file") endAnd you probably want to change:
fs.open("/path/to/file", "r")to:
local file = fs.open("startupprogram.txt", "r")
MysticT, on 11 June 2012 - 07:25 PM, said:
blipman17, on 11 June 2012 - 07:09 PM, said:
if fs.exists("startupprogram.txt")~="false" thenIt returns always true, because the boolean returned by the function will always be different from the string "false". So it tries to open the file, wich doesn't exist and returns nil.
if not fs.exists("startupprogram.txt") thenAnd you should always check the file handle returned by fs.open:
local file = fs.open("/path/to/file", "r") if file then -- use the file file.close() -- don't forget to close it else print("Error opening file") endAnd you probably want to change:
fs.open("/path/to/file", "r")to:
local file = fs.open("startupprogram.txt", "r")
MysticT, on 11 June 2012 - 07:25 PM, said:
blipman17, on 11 June 2012 - 07:09 PM, said:
if fs.exists("startupprogram.txt")~="false" thenIt returns always true, because the boolean returned by the function will always be different from the string "false". So it tries to open the file, wich doesn't exist and returns nil.
if not fs.exists("startupprogram.txt") thenAnd you should always check the file handle returned by fs.open:
local file = fs.open("/path/to/file", "r") if file then -- use the file file.close() -- don't forget to close it else print("Error opening file") endAnd you probably want to change:
fs.open("/path/to/file", "r")to:
local file = fs.open("startupprogram.txt", "r")
Posted 11 June 2012 - 07:37 PM
MysticT, on 11 June 2012 - 07:25 PM, said:
blipman17, on 11 June 2012 - 07:09 PM, said:
if fs.exists("startupprogram.txt")~="false" thenIt returns always true, because the boolean returned by the function will always be different from the string "false". So it tries to open the file, wich doesn't exist and returns nil.
if not fs.exists("startupprogram.txt") thenAnd you should always check the file handle returned by fs.open:
local file = fs.open("/path/to/file", "r") if file then -- use the file file.close() -- don't forget to close it else print("Error opening file") endAnd you probably want to change:
fs.open("/path/to/file", "r")to:
local file = fs.open("startupprogram.txt", "r")
0 members, 1 guests, 0 anonymous users