file browser in blender

Hi guys, i need to make a game that can load saved games. But i want that the user can select which game to load; so im trying to make a “file browser” but its so very complicated to do it from scratch and im having a hard time finding similar works on the net.

Hence i post here :stuck_out_tongue:

Well, the "easy way, is to do a “select scene” with the available files/icons that the player could choose, like in YoFrankie menus, for ex.

To allow the user to choose which file he wants to load you can create fixed files and create slots that load each file. Like in the old games (Mario64,DK,etc…)

But if you want to allow the user to save and load the games in any folder than you will need the user to write the exact location where he wants the file to be saved/loaded (Eg:“C:\Users\MyName\Desktop\Game\Saves”) or you can make a file browser but to do that in the game engine it will be really difficult. Basically you will need a scrip to read the current location of the file and read all files in that folder, than show their icons and finally load the selected file or save in the current folder.

You could have a specific directory that the saves go in nested in the games main folder (ie MainGameFolder\Saves) and then import the os module in python to walk through the saves directory. Something like this (I’m at work, so I can’t test this code, more of an idea really):

import os

dir = "C:\\MyGame\Saves"

saved_games = os.listdir(dir)

for save in saved_games:# Then pass each file name to the BGE to do something with it

Sorry, I realise code fragments aren’t always too helpful, if I get time I’ll post a .blend example.

You can get the blend file directory with expandPath("//")

dir = GameLogic.expandPath("//Saves")

I’m getting somewhere with building a file browser. It uses text files in .ini format for the saved game data as they’re a tidy way to store data and the handy configparser makes pulling specific variables from it easy (no need to keep track for what lines being read as with readline() methods, though they should still work when loading the files). The script should be able to be easily modified for other file types.

So far it uses the os module to search for files in a saved game folder and reads through them (with configparser) extracting the name of the save, date of save and time of save. The results are then displayed in the GE by using the addobject actuator to add planes with a Text property showing the each saved files details and position the plane accordingly.

All thats left to do is allow the user to select the file to load and load it. Also need to add a fillter for file types - otherwise the script attempts read any file that finds its way into the saves folder, and a check for valid saves. And finally a passable GUI, at the moment the displayed file browser looks rubbish.

Working blend file to follow soon.

Finally, a working version for my file browser for blender. Just a rough version, I’m sure there’s better ways to do this.

To play you need to extract the whole file browser folder and run it from there. Make sure you’re on the scene Game_1 before you play (pressing play on the load scene crashes it). While playing press F6 to open the file browser and load new player positions (press the lame looking box that looks like it could be a load button).

Here’s the blend:

I’ve got some improvements planned, but thought I’d get some feedback on it so far. I plan to plug it into Socials FPS template when the full save/load and file browser system is complete.

The save files are simple to edit with notepad so you can copy/delete/edit them to see how it handles with different file numbers and settings

rying this thing on 4 diferent machines and i cant get it working.

Windows P4:
I got a message saying “Shaders not supported”, so im guessing its a video card problem. nothing to do here…

Windows i3 (ATI Radeon 1GB):

I got this output:
C:\Users\rica\Desktop\File Browser>“c:\Program Files\blender-2.49b\blender.exe”
Compiled with Python version 2.6.1.
Checking for installed Python… got it!
Detected GL_ARB_texture_env_combine
Detected GL_ARB_texture_cube_map
Detected GL_ARB_multitexture
Detected GL_ARB_shader_objects
Detected GL_ARB_vertex_shader
Detected GL_ARB_fragment_shader
Detected GL_ARB_vertex_program
Detected GL_ARB_depth_texture
Detected GL_EXT_separate_specular_color

Blender Game Engine Started

unable to initialize image(0) in MAtext, image will not be available
unable to initialize image(0) in MAtext_loc, image will not be available

Blender Game Engine Finished

Max OS X quad core xeon (NVIDIA GeForce GT 120):
Blender Game Engine Started

unable to initialize image(0) in MAtext, image will not be available
unable to initialize image(0) in MAtext_loc, image will not be available
Python script error from controller “cont#CONTR#1”:
Traceback (most recent call last):
File “”, line 74, in <module>
File “/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/”, line 292, in get
ConfigParser.NoSectionError: No section: ‘Save Details’

Blender Game Engine Finished

Windows intel-based system:

same with the no shaders… but it seems to load the files, but i dunno how to get this working