Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Akow, TipmyPip, tomaslolo), 788 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 5
Reading a config.ini #253202
02/23/09 13:45
02/23/09 13:45
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline OP
Serious User
MrGuest  Offline OP
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
I've seen this posted a few times so here's the simple way i do it.

Code:
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
Code:
	get_user_settings("config.ini");
and change as necessary, (e.g multiple user settings)

then your config file should look something like this
Quote:
[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: MrGuest] #254146
03/01/09 12:36
03/01/09 12:36
Joined: Jul 2007
Posts: 424
EUROPE
maslone1 Offline
Senior Member
maslone1  Offline
Senior Member

Joined: Jul 2007
Posts: 424
EUROPE
Thanx!


A8c, Blender, FlStudio, Unity3d
Re: Reading a config.ini [Re: maslone1] #254150
03/01/09 13:16
03/01/09 13:16
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
you can use the win32 api functions

GetPrivateProfileInt
GetPrivateProfileSection
GetPrivateProfileString
WritePrivateProfileString

for this purpose.

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 Offline
Serious User
Nidhogg  Offline
Serious User

Joined: Dec 2006
Posts: 1,086
Queensland - Australia
Originally Posted By: Joey
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 Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Here is a small example on how to use GetPrivateProfileString and GetPrivateProfileInt.

Test.c
Code:
#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
Code:
[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 Offline
Serious User
Nidhogg  Offline
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: Nidhogg] #261522
04/18/09 09:12
04/18/09 09:12
Joined: Mar 2007
Posts: 99
Germany
zSteam Offline
Junior Member
zSteam  Offline
Junior Member

Joined: Mar 2007
Posts: 99
Germany
MrGuests solution is the best one for me. But how can I write into the ini file? It would be very usefull for me and all the other 3dgs members^^


=> www.alrik-online.de
A7 Commercial
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 Offline
Junior Member
zSteam  Offline
Junior Member

Joined: Mar 2007
Posts: 99
Germany
could it be possible with this script?


=> www.alrik-online.de
A7 Commercial
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 Offline
User
Schmerzmittel  Offline
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:
Quote:
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 Offline
Expert
EvilSOB  Offline
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

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1