How to count files

Monkey Forums/Monkey Programming/How to count files

Tri|Ga|De(Posted 2012) [#1]
I have some levels in my new games.
level1.json
level2.json
.
.
.
levelN.json

How do I read the number of files so I can determine the number N?

I know of cause the I know the number of files but I just want to make the automatic count the levels for me.


Amon(Posted 2012) [#2]
Store the level number in a variable 'num' then + it on to the 'level'.

level+""+num+"".json

I can't recall the exact way in Monkey but in BlitzMax I used something Similar.


Beaker(Posted 2012) [#3]
Clunky but can you not do a For loop that counts to 100 trying to load 100 files and then check which files actually loaded something?


Tri|Ga|De(Posted 2012) [#4]
I think you misunderstand me.

I have a numer og files with my level data and I want my game to count how many files I have.
I know that I know this number, but I just don't want to change a variable each time I add a new level. And I do have some plans on letting the player add levels to the game later on.


Gerry Quinn(Posted 2012) [#5]
Look at bananas/picpuzzle - it loads an arbitrary number of picXXX.jpg files.

If you just want to count them, you could just load them all into the same temporary object - though there is probably some way to do it more efficiently in native code.


Gerry Quinn(Posted 2012) [#6]
Look at bananas/picpuzzle - it loads an arbitrary number of picXXX.jpg files.

If you just want to count them, you could just load them all into the same temporary object - though there is probably some way to do it more efficiently in native code.