Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / DBPro: A method of loading data from configuration files without the need for addins

Author
Message
jasuk70
21
Years of Service
User Offline
Joined: 3rd Dec 2002
Location: Hemel Hempstead
Posted: 10th Jul 2004 12:07
Firstly here is the code:



This contains 2 main functions for geting information out of the config files.

Int=GetConfigInt("Details")
and
String=GetConfigString("Details")

The details part is a single string seperated by .'s

In the first position is the config file name
In the second postion is the section in the config file
in the third postion is the parameter you want to read. So in the above code there is the following example

Int=GetConfigInt("main.screen.width")

This will open a file called "main.conf" look for a section called screen and return the contents of parameter width.

The way the above code works means the config file needs to have a :screen: piece of text and it will look from that point until it reaches a ; for the string width. The config files required for the example above are:


main.conf
:screen:
name=Test Screen
width=1024
height=768
depth=32
;

:window:
name=Test Window
width=100
height=100
;

:runtime:
debug=1
;


network.conf
:defaults:
ip=127.0.0.0
hostname=localhost
gameport=1111
;

for the above code you need to create a sub directory in your project folder called gamedata and put the 2 above text config files in this directory.

I hope some people find this useful. Any problems with it then let me know.

Jas

----
"What is this talk of 'release'? Klingons do not'release' software. It escapes leaving a bloody trail of developers and quality assurance people in its wake!"

Login to post a reply

Server time is: 2024-11-23 19:46:47
Your offset time is: 2024-11-23 19:46:47