3 registered members (Akow, TipmyPip, tomaslolo),
788
guests, and 11
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Reading a config.ini
#253202
02/23/09 13:45
02/23/09 13:45
|
Joined: Jul 2008
Posts: 1,178 England
MrGuest
OP
Serious User
|
OP
Serious User
Joined: Jul 2008
Posts: 1,178
England
|
I've seen this posted a few times so here's the simple way i do it.
STRING* str_file_data = "";
var _fHandle_user_config_i = NULL;
function get_user_settings(STRING* local_filename){
_fHandle_user_config_i = file_open_read(local_filename);
if(_fHandle_user_config_i){ //read config file
int eof = 0;
while(eof != -1){
eof = file_str_read(_fHandle_user_config_i, str_file_data);
var_for_name(str_file_data);
}
}
file_close(_fHandle_user_config_i);
} then call from another function get_user_settings("config.ini");
and change as necessary, (e.g multiple user settings) then your config file should look something like this [input devices] 1 joystick 2 keyboard/mouse _input_1_device = 2
[camera mode] 1 1st 2 3rd 3 orbit 4 world _camera_mode = 2
[player settings] _player_inverse_move_x = 1 _player_inverse_move_y = 1 _player_inverse_turn_x = 1 _player_inverse_turn_y = 1
_player_movespeed = 1.8 _player_turnspeed = 1.5 Hope this helps
|
|
|
Re: Reading a config.ini
[Re: Joey]
#260110
04/08/09 22:27
04/08/09 22:27
|
Joined: Dec 2006
Posts: 1,086 Queensland - Australia
Nidhogg
Serious User
|
Serious User
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
|
you can use the win32 api functions
GetPrivateProfileInt GetPrivateProfileSection GetPrivateProfileString WritePrivateProfileString
for this purpose. Don't know if you'll read this Joey but if you do could you please post an example on how to use the above API's. Thanks in advance.
Windows XP SP3 Intel Dual Core CPU: E5200 @ 2.5GHz 4.00GB DDR3 Ram ASUS P5G41T-M LX PCIE x16 GeForce GTS 450 1Gb SB Audigy 4 Spyware Doctor with AntiVirus
|
|
|
Re: Reading a config.ini
[Re: Nidhogg]
#260159
04/09/09 07:45
04/09/09 07:45
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Here is a small example on how to use GetPrivateProfileString and GetPrivateProfileInt. Test.c #include <acknex.h>
#include <windows.h>
STRING* path_to_ini = "#256";
char result_chr[32];
int version_;
void main()
{
STRING* temp_str = "#32";
version_ = 0;
str_cpy(path_to_ini,work_dir);
str_cat(path_to_ini,"\\test.ini");
GetPrivateProfileString("header","game_name","can't read string",result_chr,32,_chr(path_to_ini));
version_ = GetPrivateProfileInt("header","game_version",0,_chr(path_to_ini));
str_cpy(temp_str,result_chr);
str_cat(temp_str," v");
str_cat(temp_str,str_for_num(NULL,version_));
video_window(NULL,NULL,48,temp_str);
} and test.ini [header]
game_name=Test
game_version=1 And here is the MSDN reference of these functions: GetPrivateProfileString GetPrivateProfileInt I hope this help you
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Reading a config.ini
[Re: WretchedSid]
#260204
04/09/09 12:41
04/09/09 12:41
|
Joined: Dec 2006
Posts: 1,086 Queensland - Australia
Nidhogg
Serious User
|
Serious User
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
|
Thankyou very much, Appreciate the assistance.
Windows XP SP3 Intel Dual Core CPU: E5200 @ 2.5GHz 4.00GB DDR3 Ram ASUS P5G41T-M LX PCIE x16 GeForce GTS 450 1Gb SB Audigy 4 Spyware Doctor with AntiVirus
|
|
|
Re: Reading a config.ini
[Re: zSteam]
#262175
04/22/09 09:59
04/22/09 09:59
|
Joined: Mar 2007
Posts: 99 Germany
zSteam
Junior Member
|
Junior Member
Joined: Mar 2007
Posts: 99
Germany
|
could it be possible with this script?
|
|
|
Re: Reading a config.ini
[Re: zSteam]
#263697
05/01/09 14:59
05/01/09 14:59
|
Joined: Aug 2005
Posts: 512 Bayern
Schmerzmittel
User
|
User
Joined: Aug 2005
Posts: 512
Bayern
|
Ive tryed a lot with the Lite-C functions, but it wont work to write behinde i.e. the game_name = I could read any value i want, but i couldnt write behind the value. Does any1 know how to do it? The GS Manual says for file_open_write: Opens the file with the name string to write text, with the previous content will be overwritten. If the file is in savedir does not yet exist, it will be recreated. Can anyone help on this? Greetings Schmerzmittel
A7 Com V7.80
|
|
|
Re: Reading a config.ini
[Re: Schmerzmittel]
#263744
05/01/09 23:46
05/01/09 23:46
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
If you want to stick to lite-c functions being able to write into the center of an existing file, Check THIS thread out. Any questions, ask over there...
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|