This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
LewisTehMinerz's profile picture

Frame splitting w/ NFA file format

Started by LewisTehMinerz, 13 July 2015 - 04:30 PM
LewisTehMinerz #1
Posted 13 July 2015 - 06:30 PM
Hello. I am trying to develop a program that can split the frames up in an NFA file.

The framesplit program is Pastebin ID: 5jkpZRj6
The test.nfa is Pastebin ID: KneqXszu

Please help!

I know the ending of a frame is the ~ character. It splits up the first frame fine, but 2 and 3 are completely blank.

Thanks!
KingofGamesYami #2
Posted 13 July 2015 - 06:33 PM

    for x = startf, endf do
      if f.readLine( x ) == endchar then --#if this line is equal to the end character
        frameend = true --#end the loop
        lineend = x
      else --#else
        framebuffer[ x ] = f.readLine( x ) .. "\n" --#add the NEXT line to the file
        --print( framebuffer[ x ] )
      end
    end

…see the problem?
LewisTehMinerz #3
Posted 14 July 2015 - 04:08 PM

framebuffer[ x ] = f.readLine( x ) .. "\n" --#add the NEXT line to the file

Is this what your talking about?

The reason I told it to add \n is because:
  1. No where else in the program does it append \n
  2. I'm lazy, so I append it now.
  3. It doesn't automatically add \n
KingofGamesYami #4
Posted 14 July 2015 - 07:37 PM
I don't care about \n. I care that your reading the NEXT LINE not the line you just compared.


   --#is this line the end character?
                       7777777         --#no, lets save this line to the table      
                      7       7777          --#is this line the end character?
            77777777  77         77        --#no, lets save this line to the table
            777777777777          7        --#is this line the end character?
          777       77777777     77        --#no, lets save this line to the table.
         77             7777777777          
         7                  777            
         7                     777          
         7                       77        
         777                      7        
            77                   77        
              7777            777          
                  77777  77777              
~


             7                              
             777       7777777              
                777   7       7777          
            777777777 77         77        
            777777777777          7        
          777       77777777     77        
         77           777777777777          
         7             77   777            
         7              77     777          
         7                       77        
         777                      7        
            77                   77        
              7777            777          
                  77777  77777              
~


             7                              
             777       7777777              
                777   7       7777          
            777777777 77         77        
            777777777777          7        
          777       77777777     77        
         77           777777777777          
         7             77   777            
         7              77     777        77
         7                       77     777
         777                      7777777  
            77         777777777777        
              7777    77      777          
777777777777777777777                  77777  77777

Which means your table is going to end up saving lines 2, 4, 6, 8, 10, 12, 14, 16, etc. and scanning lines 1, 3, 5, 7, 9, 11, 13, 15, etc.
Edited on 14 July 2015 - 05:38 PM
LewisTehMinerz #5
Posted 15 July 2015 - 06:07 PM
Incorrect.


if f.readLine( x ) == endchar then
		frameend = true
		lineend = x
	  else --#ELSE
		framebuffer[ x ] = f.readLine( x ) .. "\n"
		--print( framebuffer[ x ] )
end

This is basically scanning the line if it's the end char.
If so, add the line you are on to "lineend"
If it's not the correct line, then ignore it and add it to the table. –#ELSE
There is an else there, which says if it's not the line your looking for, add it to the table.
Edited on 15 July 2015 - 04:08 PM
KingofGamesYami #6
Posted 15 July 2015 - 06:43 PM
Every time you call f.readLine it gives you a new line. f.readLine does not accept an argument.
LewisTehMinerz #7
Posted 18 July 2015 - 11:07 AM
Still gives the same result w/out arg.
Bomb Bloke #8
Posted 18 July 2015 - 01:43 PM
Which for all we know means you didn't bother to re-organise the rest of your code to account for the fact that the argument is ignored, perhaps?

You also seem to be forgetting to set "frameend" back to false, which'd be why you're only getting data from the first frame.

Personally I'd script things out along these lines:

write( "Enter the location of the animation: " )

local f = read()

write( "Prefix for files: " )

lcoal framename = read()

print( "Writing files. Please wait..." )

local curFrame = 1
local output = fs.open(framename..curFrame, "w")

for line in io.lines(f) do
	if line == "~" then
		curFrame = curFrame + 1
		output.close()
		output = fs.open(framename..curFrame, "w")
	else
		output.writeLine(line)
	end
end

output.close()