Page 1 of 1

level chooser

PostPosted: Sun Dec 19, 2010 9:00 pm
by Fojam
scenerio:
I have an executable file for my game, and all of the levels for that game are .dat files. I want to be able to create new levels without modifying the executable file.
Is there a way for game editor to list all of the .dat files in a certain directory so you can choose which one to launch when you start the game?

Re: level chooser

PostPosted: Sun Dec 19, 2010 10:28 pm
by lcl
There is an easier way. You need to make a variable for the number of level to load.
Then when you need to load next level, you can write this code:
Code: Select all
char level[30];
sprintf(level, "level%i.dat", levelNumber);
loadGame(level);

Now you can make it so user can choose the number of level to load.
If you use this code, your levels must be named like level1, level2, ...

The code is untested but it should work. If it doesn't, I'll fix it and then send to you again. :D

Re: level chooser

PostPosted: Mon Dec 20, 2010 1:48 am
by Fojam
Thanks but I'm looking for a way to be able to create custom levels anytime I want and for the game to list all of the levels I have in a particular folder and let me choose the level I want

Re: level chooser

PostPosted: Mon Dec 20, 2010 6:37 am
by skydereign
You might try this. I've set this up and it works quite nicely. Create a file that has the names of all the levels within the directory. You can do this through a string array, or by exterior text files. The text files are easier, and can be edited without a game, but can be edited by other users (in this case it doesn't matter). Then your level loader menu type file will load up that list, and use LoadGame(stringVar). I set up a login system and other with this, for multiplayer interaction within other levels, so it should work just as said. But, if you do need any more explanation, ask.

Re: level chooser

PostPosted: Mon Dec 20, 2010 11:38 pm
by skydereign
There is no way of reading into the directory currently, which is why the string file is needed. Whenever you add a game, you will need to change the file, its the only way to know what is in the file. You could create a program not in gameEditor that updates that file, but it needs to be there.

Re: level chooser

PostPosted: Mon Dec 20, 2010 11:42 pm
by Fojam
if you install the dat files via debian, is there a way to just add a string to that text file without affecting the rest of the text file?