Is it possible to populate an array with information from a text file. The info in the text file would just be numbers on different lines. I've no idea how to do this, any help would be appreciated
Thanks for your help earlier, I've got this so far:
fn getNumbers =
(
local listArray = #()
fileS = openFile "C:\\numbers.txt" mode:"r"
while not eof fileS do
(
lineInfo = readLine fileS
append listArray lineInfo
)
close fileS
for i in listArray.count do
(
print i
)
)
My only problem is that my last for loop doesn't work. If I print listArray just after close fileS it returns the numbers in the text file. With the last for loop in I get errors in my script:
-- Error occurred in getNumbers(); filename: C:\Program Files (x86)\Autodesk\3ds Max 2008\Scripts\generator.ms; position: 263
-- Frame:
-- lineInfo: "3333333333"
-- listArray: #("1111009921", "9999001119", "3333333333")
-- files: <File:C:\numbers.txt>
-- No "map" function for 3
Replies
look in documentation for "FileStream Values"
make a function to do this, quite easy. open the file, read each line, if it is ints you want convert the string to int and bingo.
good luck!
My only problem is that my last for loop doesn't work. If I print listArray just after close fileS it returns the numbers in the text file. With the last for loop in I get errors in my script:
should be
or you could do it this way
"for x in y do" only works on arrays, your giving it an integer (listarray.count). for large data sets use the second method as its much faster.
Thanks for explaining that. The 2nd method you suggest works brilliantly. Thanks. :thumbup: