Another thing about the opening and reading of the AS file format for script use is to open the file to read it, but only advance one line at time.
For instance with the code you used for finding the actions... works perfectly. Scan all the lines in a loop, find the values and you're done.
However for my purposes I need to read in only the lines AFTER the bone name has been found (for save/load) I want to STOP the reading of lines at the point and advance through each line one at at time to find the key values.
So I will use the same thing I'm using in the load bone animation script.
The variable "fileToOpen" is opening the file represented by "path" and the "r" means it is read only.
--------
Using the *a option would read in the whole file into the variable "hugeTextString". I now have a "copy" of the whole file in a really big string variable.
Code: Select all
hugeTextString = fileToOpen.file:read("*a")
------
Or I could use any of the other "file:read()" options:
*a - reads and returns the whole file.
*n - reads and returns the next number.
*l - reads the next line (default)
number - reads and returns exactly the number of characters represented by the number:
fileToOpen.file:read(5)
------
With no option this will read in the next line (same as *l) and assign it to "myData".
Or I could read in the next number in the current line:
Code: Select all
myData = fileToOpen.file:read("*n")
By using the *n I don't have to use any regex. It skips any spaces and reads the next number in the line.
------
Once I find the line in the AS file that represents the bone, I can keep reading line by line until I find "Keys". Then read those lines one at a time to get the key interpolation value.
Once one bone is done I can advance in a loop until I find the name of the NEXT bone and do it all again.
As you can see... this is why I loath parsing the file format. It isn't always easy.
-vern