I'm new to scripting with George and trying to load images from a text file. I have TVPaint requesting the import file correctly and then sending the resulting path to a function that reads the text file (based on this function from the George wiki). My issue is that when I try to store each line from the text file in a LOCAL array and return it, it doesn't print as I'd expect. If I check its values before the return, however, it prints correctly. Can George return an array? If so, can someone please help me understand how to return this array correctly? Thank you!
Code: Select all
tv_ReadUserString fileRequest 0
parse result path
tv_ReqFile "Select file to import|"path"||*.csv"
parse result file
if (cmp(file,"Cancel") == 0)
array1 = file_readTextFile(file)
//set to 2 for testing purposes
rowLength = 2
FOR i = 0 TO rowLength
tv_warn "array1 " i " = " array1[i]
//returns array1 0 = array1.0
//returns array1 1 = array1.1
//returns array1 2 = array1.2
END
end
FUNCTION file_readTextFile(textFilePath)
LOCAL myReturn fileExists i line text
tv_WriteTextFile "Exists" textFilePath
fileExists = result
IF CMP(fileExists,textFilePath)==1
loop = 1
i=0
//while loop iterates until end of file
WHILE loop==1
tv_readtextfile i textFilePath
PARSE result line text
IF CMP( line, "EOF" ) == 1
loop=0
rowLength = i
ELSE
length = LEN(text)
// length of line of text
length=length-2
text = CUT(text,1,length)
//'text' variable is a line of text
myReturn[i]=text
END
i=i+1
END
END
print myReturn[0]
//prints correctly
RETURN myReturn
END