Need help with numeric padding in image sequences

Blitz3D Forums/Blitz3D Beginners Area/Need help with numeric padding in image sequences

Avrigus(Posted 2008) [#1]
Hello everyone,

I have an image sequence that i'm loading into an array but i'm having problems due to numeric padding. My sequence has more than 10 frames so for the sake of previewing my sequence in an image viewer I need to index the first nine frames as: run_01.png, run_02.png, etc.

When I try to load the image sequence into an array it doesn't seem to like the numeric padding although when I manually strip the padding (by renaming the files run_1.png, etc) the sequence loads into the array perfectly.

Does anyone know how I can retain the numeric padding and load my image sequence into an array?

Cheers!


TomToad(Posted 2008) [#2]
Use something like this:
Filename$ = "run_"+right("0"+frame,2)
The problem with using just "run_"+frame is that the leading 0 will be truncated. By using a string 0 (by putting it in quotes) will make sure it is not truncated and by using the Right() command will make sure that you don't start getting run_010, run_011, etc...


Avrigus(Posted 2008) [#3]
Hey TomToad,

I actually tried a similar technique but ran into problems when the sequence hits 10. Here's the code I used adapted from your code (frames 10 - 14 load correctly using this method):
Dim tex (14)
For t = 1 To 14
tex(t) = LoadTexture ("images\run_" + Right ("0" + t, 2) + ".png",1+2)
Next


I assume I may need a function to get rid of the "0" once the array reaches 10. Any ideas?


TomToad(Posted 2008) [#4]
that's what the Right() does. It takes the rightmost two characters of the string. So from 0 - 9, you get 00 - 09 and Right() simply takes those two characters. When you have 10-14, you get 010 - 014 and Right() will take the last two characters, ignoring the leading 0, so you're back to 10-14
Run this program to see it in action
For t = 1 To 14
	Print "run_"+Right("0"+t,2)+".png"
Next
WaitKey()



Avrigus(Posted 2008) [#5]
Awesome mate, that worked like a charm. my original code worked after I encapsulated the t: (t). Thank you very much for you help, it is a nice and elegant solution :-)