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.

Dark GDK / .ini files with GDK

Author
Message
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 23rd Dec 2009 18:26
Well, I was wondering if it is possible to use .ini files to save de value's of my options ( like the selecten resolution, windowed/not windowed and all those video option ) and which header files I need to include to make use of them and basicly how to use them. So does anybody have a tutorial or somthing like that?

Isocadia
Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 23rd Dec 2009 18:36 Edited at: 23rd Dec 2009 18:36
I personally wouldnt use ini files anymore. The simplest way would just be to use a text file. Or a .xml sheet may be a faster option.

This is a helpful tutorial on how to read and write from files. You could read from a ini file i believe. Though if you are sticking with the standard formatting of

[settings]
resolution=800x600

then you will need some additional code.


http://www.cplusplus.com/doc/tutorial/files/
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 24th Dec 2009 04:38
You might want to use a LUA script with DarkGDK as an .ini files.

http://forum.thegamecreators.com/?m=forum_view&t=155919&b=22
They use something called DarkLUA for integrating LUA.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 24th Dec 2009 07:20 Edited at: 24th Dec 2009 07:22
I dont know why people hate INI files so much, but I have always found it very useful and easy to use.

I also personally use the extension *.SET rather than *.INI for my setup files because later versions of Windows have a nasty habit of messing around with files with *.INI extensions with that name.

The 3 most important functions that you require for handling INI file information are:
GetPrivateProfileIntA()
GetPrivateProfileStringA()
WritePrivateProfileStringA()

Of course there are more of these to handle other numeric types.

Here is a bit of sample code that I used to read and save changes for networking port numbers and network IP numbers.



Hope that gives you something to work from.
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 24th Dec 2009 09:27
@sydbod: I think I understand what is happening there, but those commands are in what header file? And in this command:

You get this from client.set?:

Or are you doing something else?

Isocadia
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 24th Dec 2009 13:22 Edited at: 24th Dec 2009 13:23
The DarkGDK header files already load the necessary Platform SDK header files to give you access to all the required functions for working with INI files, so you have to add no new headers to your project.

This will be the contents created and read from the "Client.set" file being used as an INI file.


Quote: "
[ClientSetup]
UseIP=127.0.0.1
UsePort=6790
ServerIP=127.0.0.1
ServerPort=6789
"


These are the default values if the player does not want to enter different values for the game to use. If the player enters different values when the entry screen queries him, then the entered values will get overwritten into the Client.set file.

Do a Google search on the net for the commands.

The beauty about using the commands is that they have default values if an entry does not exist in the INI file.

If you have any problems, just post what entries you are trying to use and their default values, and I will knock up a quick code sample for you to see how it looks like.
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 24th Dec 2009 13:28 Edited at: 24th Dec 2009 13:40
So basicly this :
tells that is there is nothing it should use the values put in there, but if there is something in the .set file, it will load that under the string name UseIP ( as an example ). I think I'm starting to understand. Because mainly what I want right now is to make a options screen where people can edit their resolution and grapics detail etc. then when they close that window it save everything to the .ini file and when you restart the game your changes took place.

Isocadia

Edit: Under what term should I search in google for the commands?
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 24th Dec 2009 13:45 Edited at: 24th Dec 2009 13:49
YEP you basically have it.

Here is another simple sample that I used when trying another game engine.
I used a data structure to store the setup info into.

The data structure:


The usage:


The result


Notice how one normally does the reads first.
If there is data read then we use it or the default data if data is not being read.
Then we follow with writing the data back into the INI file so that it gets recreated no matter if the data is there or not there.

Normally in the game if the INI file becomes corrupted, it is just a matter of erasing the corrupt INI file and automatically a new default valued INI file will automatically get recreated.

EDIT: for google search just search for the functions
EG:
GetPrivateProfileStringA()
etc
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 24th Dec 2009 14:09 Edited at: 24th Dec 2009 14:30
Well, right now I'm trying to make my own .set file work. There is just one thing I don't understand about you code:
1st: This maybe because I'm still kinda noobish to C++, but what is pProgram?
2nd: For you program to work, the file must already exist, it does not make a file if it does not exist?

Well, that was it. Hope I will get my own working soon.

Isocadia

Edit: Well This is what I got right now:



And the .set file:



But when I run this, I get this error:



What am I doing wrong??
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 24th Dec 2009 14:39
Not a problem ... let me explain.

Firstly, any of the write commands will automatically create a new file if it does not already exist. The commands take care of that all by themselves so you don not have to worry about it yourself.
As I said before ... I find working with INI type files and their commands very easy because of all the automatic background tasks that they do.

Now .. how does the code work. (I have used pointers so that is probably what is confusing you a bit)

I defined a new data type that is a structure.(a collection of values under the one data type.



The new data type is called "ProgramSettings". it is a data type that is made up of the collection of data types specified in its definition.

Now we want to create a variable that is created the same as that data type.



pProgram is just a variable name that has now been created and has variables in it the same as the data type.

We can get access to each of the parts of the newly created "pProgram" structure elements this way (we are using pointers)
pProgram->iDesktopWidth
to get access to the integer value for the entry "iDesktopWidth" that is in the variable called "pProgram" that is structured like the data type "ProgramSettings".

I hope that helps a bit.
sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 24th Dec 2009 14:48 Edited at: 24th Dec 2009 14:58
Let us just use integer variables rather than structures, and use your code.





Try that.

EDIT: did some changes, please retry it.
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 24th Dec 2009 16:06
It works, thanks alot.

Isocadia
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 24th Dec 2009 19:24
Yeah, I don't know why people hate INI files so much either - less overhead than xml... then again - xml has it's place as well.

Shoot my most instense config files I write usually are along the lines of:

somename=somevalue

kinda like apache httpd web server configuration files. when they want a group... they just use tags like xml then...

<somegroup1>
somename1=somevalue1
somename2=somevalue2
</somegroup1>

<somegroup2>
somename1=somevalue1
somename2=somevalue2
</somegroup2>



Cetobasilius
14
Years of Service
User Offline
Joined: 29th Dec 2009
Location: Mexico
Posted: 29th Dec 2009 11:42 Edited at: 29th Dec 2009 12:49
i wanted to have that in my game too but no one knew how to. so i came with a way of reading the configuration file. My file is in plain TXT format but i guess there would be no trouble since INI files are almost if not the same as txt... well heres my code:


well thats for reading... guess for writing maybe use the GDK integrated file capabilities. Obiously this code is before the loop, and some global variables need to be defined/stated dont know what the word is XD.. dont know if i missed something...

my txt file has the following and it works great:

Resx=800
Resy=600
ResDepth=32
Fullscreen=0

MediaFolder=media\\




...
if you have any doubt i will be glad to help out. i searched and searched and no answer to this problem so i had to do it myself x_x

hi
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 2nd Jan 2010 20:31
Well, I sorta got the .set file to work. But, I got a variable called windowed. The default is 0 ( FS ) but in the .set file I changed it to 1 with notepad. The screen is windowed. But when I change it to 0 the screen stays windowed. Here is the .set file:



and the code to load:



and the code to use:



It could be that I am missing something. But when I remove the if function, I amm in full screen and my stats say that windowed is 0, and the moment I put the if statement back it is windowed again and my stats says that windowed = 1.

Hope you can help me,

Isocadia

sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 3rd Jan 2010 03:48 Edited at: 3rd Jan 2010 03:50
HINT......
What is wrong with
Quote: "if ( Windowed = 1 ) "


and also wrong with
Quote: "else if ( Windowed = 0 ) "


EDIT: when does one use "=" and when does one use "=="
Isocadia
15
Years of Service
User Offline
Joined: 24th Jul 2009
Location:
Posted: 3rd Jan 2010 17:24
one uses = when defining variables, == to see if a variable contains a certain value. How could I oversee that xD. Thanks for pointing that out.

Isocadia

PS: Definition may be a bit off, since english is kinda bad.

sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 4th Jan 2010 03:49
You are doing fine.
Hate to think of how many times I have made the same mistake.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 4th Jan 2010 05:06
Same here (I've done that many times) - but I don't dislike that feature because.. well I don't have a great example but I've used it purposely ... like

if( StoreResult = MYFunctionCall() ) {
do this...
}else{
do that...
};

..down here..
if(StoreResult){
blah blah
};

So - it's actually a nice powerful thing - but as with all coding, just takes one character to hose everything! (Particularly annoying in javascript cuz stuff just stops working often without a good error message to get you even close to what is causing the failure)

--Jason

sydbod
16
Years of Service
User Offline
Joined: 14th Jun 2008
Location: Just look at the picture
Posted: 4th Jan 2010 18:25 Edited at: 4th Jan 2010 18:30
@ Jason,

I also tend to do similar things, but many professional programmers tend to take offence to it.
The argument (as has been argued on many sites) goes like this.

True = 1
False = 0

if one uses for example
variableX = 3
if(variableX){

Then the condition in that if statement will be treated as True.

The trouble is that True != 3 , True == 1

so the correct format should be
variableX = 3
if(variableX != 0){
OR
if(variableX != False){

I think this situation has come about because when the code gets compiled, the machine code only has access to "jump if 0" and "not jump if 0" instructions.
So there appears to be this standard that states that
True = 1 should always be used and if you want to allow other numbers to be tested for true, then you should always test them for not being 0.

It is one of those funny situations that have no real practical influences to the operation of the code, but it has sure created some massive and very bitter arguments.
jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 4th Jan 2010 19:07
Yeah - true - some coders get their feathers ruffled over thing. In my example I was only thinking true/false so I understand that one. Most codrs hate using the result of an assignment in the if statement for reasons of debugging like this thread showed is easy to make difficult.

The other convention along these lines I think is odd but can help debugging is using this:

if( false == bSomeBoolean ) { blah };

versus

if( !bSomeBoolean ) { blah };

While we all have our own style - I try not to get my feathers in ruffle over such things. Sometimes I write code tight as heck using every parlor trick imaginable; sometimes I write more inefficient for sake of readability... usually I'm somewhere in the middle... I think conventions etc are really important - but - especially in video games - I think performance is paramount usually.

I actually think it's kind of funny when folks get all ruffled over these things that once compiled - if the program runs decent - no one ever sees or cares about.

Login to post a reply

Server time is: 2024-11-20 07:36:28
Your offset time is: 2024-11-20 07:36:28