Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » get_config_string

This thread is locked; no one can reply to it. rss feed Print
get_config_string
mscava
Member #6,815
January 2006
avatar

I'm using Allegro 4.2.1 and functiom get_config_string does not work for me. All others do ( int, float ).
string s = get_config_string( "Vars", "LogPath", "Not Read" );
s == "Not Read"

and I'm sure that section and value exist in my cfg.file ( LogPath = log.txt )

Anyone has any advice? Can this be a bug? Thanks.

CGamesPlay
Member #2,559
July 2002
avatar

No, it isn't a bug. Try this code, though.

set_config_string("Vars", "LogPath", "set value");
string s = get_config_string("Vars", "LogPath", "Not Read");

As tell me what the value is.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

mscava
Member #6,815
January 2006
avatar

Yes... It works now. s == "set value"
Well... I guess problem is in file... but I have no idea where

Could you please explain it to me?

CGamesPlay
Member #2,559
July 2002
avatar

Can you provide the file as an attachment?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

mscava
Member #6,815
January 2006
avatar

Here it is
http://www.members.allegro.cc/mscava/setup.cfg
( File also as an atachment... )

EDIT:
I see no difference between text generated by set_config_string and text written manually to notepad. Even non-visible characters are the same. Anyone has any idea what's wrong?

EDIT2: And I've found out, that it's not gonna read even file into which was written by set_config_string. Pls... help me someone...

piccolo
Member #3,163
January 2003
avatar

try that.

string s.c_str() = get_config_string("Vars", "LogPath", "Not Read");

Edit:
for a lot of allegro fountions the string must be converted to a char string

wow
-------------------------------
i am who you are not am i

Jonatan Hedborg
Member #4,886
July 2004
avatar

Piccolo, that has nothing to do with the problem. And that would most probably crash the program.

I haven't done much work with the config routines. Try posting the relevant parts of your source.

BAF
Member #2,981
December 2002
avatar

Quote:

for a lot of allegro fountions the string must be converted to a char string

Yes, when sending values in. But when assigning, string reads from char* just fine.

mscava
Member #6,815
January 2006
avatar

Here is my configuration function:

1void Setup ::
2SetupAllFromFile ( const string& path )
3{
4 CfgFile :: SetCfgFile ( path );
5 
6 string s = get_config_string("Vars", "LogPath", "Not Read");
7 Log :: SetOutputFile ( s );
8 
9 Log :: Write ( "WrapAll::Setup started initialization!" );
10 
11 Setup :: InstallDevices();
12 
13 Renderer :: RenderMode renderMode = static_cast <Renderer::RenderMode>
14 ( CfgFile::ReadInt ( "Gfx", "RenderMode" ) );
15 Renderer :: WindowMode windowMode = static_cast <Renderer::WindowMode>
16 ( CfgFile::ReadBool ( "Gfx", "WindowMode" ) );
17 
18 Renderer :: SetupScreen( CfgFile::ReadInt ( "Gfx", "ResolutionWidth" ),
19 CfgFile::ReadInt ( "Gfx", "ResolutionHeight" ),
20 CfgFile::ReadInt ( "Gfx", "ColorDepth" ),
21 windowMode, renderMode );
22 
23 Updater :: Start ( CfgFile::ReadInt ( "Game", "TimerSpeed" ) );
24 
25 FpsCounter :: Start( CfgFile::ReadBool ( "Misc", "ShowFps" ) );
26 
27 Font :: InstallFont();
28}

Everything gets initialized, only Log is associated with file 'Not Read'. Well it's the only string that is being loaded in this procedure, so I've tried even:

string s = get_config_string("Gfx", "ResolutionWidth", "Not Read");
Log :: SetOutputFile ( s );

But with the same result. Well... I'm attaching my Setup.cfg ( the file that is being read ), so someone else might try it.

I'm gonna do some more tests meanwhile... Hopefully I'm gonna find a solution.

Jonatan Hedborg
Member #4,886
July 2004
avatar

Reading numbers etc work then? How does your CfgFile class look?

mscava
Member #6,815
January 2006
avatar

Yes. Reading numbers works.

Really simple wrapper. I want to to add functionality in the future...

class CfgFile
{
  public:
    static void SetCfgFile ( const string& path );

    static string ReadString ( const string& section, const string& name );
    static int ReadInt ( const string& section, const string& name );
    static float ReadFloat ( const string& section, const string& name );
    static bool ReadBool ( const string& section, const string& name );
};

And now source file:

1void CfgFile ::
2SetCfgFile ( const string& path )
3{
4 set_config_file ( path.c_str() );
5}
6 
7string CfgFile ::
8ReadString ( const string& section, const string& name )
9{
10 return string ( get_config_string( section.c_str(), name.c_str(), "Not Read" ) );
11}
12 
13int CfgFile ::
14ReadInt ( const string& section, const string& name )
15{
16 return get_config_int ( section.c_str(), name.c_str(), -1 );
17}
18 
19float CfgFile ::
20ReadFloat ( const string& section, const string& name )
21{
22 return get_config_float ( section.c_str(), name.c_str(), -1.0 );
23}
24 
25bool CfgFile ::
26ReadBool ( const string& section, const string& name )
27{
28 return ( static_cast <bool> ( get_config_int ( section.c_str(), name.c_str(), 0 ) ) );
29}

In the example I didn't used ReadString, so I'm sure the problem is not in my class.

Well... Anyone tried to use my setup.cfg wheter it works. Or even tried to use get_config_string wheter it is not a bug?

Tomasz Grajewski
Member #4,284
February 2004

I've tested your file and it works for me. Also I'm using the get_config_string(); function many times in my custom project and never had problems with it.

It's probably bug in your code, sorry.

___________________________________________________________________________________________
mBlocks - a Tetris clone written in JavaScript | Merix Studio - website design & development | Zeitgeist

Go to: