Post by therealmethuselah on Nov 20, 2005 12:15:10 GMT -5
Name: ini Tutorial
Description: Store and Retrieve information from an .ini file
Download link: iniTutorial.zip (2.69KB)
Further comments/explanation:
.ini files are powerful and allow programmers to store data for their programs, but what if we could extend that power to saving game state data for our games. That's just what I'm going to show you how to do.
First you must have GameMaker. I suggest either 5.3a or 6.1 for this tutorial.
An .ini file has three parts.
- Section
- Key
- Value
A typical .ini file looks like the following.
[Window] would be a Section
heading is a Key
and ZeldaMaker is the value, in this case a string
In GameMaker, to write this value you would simply use this code
to read this value into your game you would have to assign it a variable, like this...
As you can see, .ini files are powerful, and very easy to read/write.
This showed you how to store data you had written, but what if you already had the value in your game, and wanted to write it to a Players Save file... you would use the following code.
and voila! you have a save state file.
The file would look like this when written
Also, remember that .ini files HAVE TO reside in the same folder as your .exe file. So if you are storing them somewhere else, make sure they are moved/copied to your working_directory, before reading/writing.
I know what you're thinking... "But can't someone just open up your file and cheat"... yes!, but not if we include some kind of encryption/decryption.
There are plenty of encryption/decryption algorithms, as well as .dll files on the GameMaker forums.
If you have any questions on how to implement something like this, don't hesitate to email me at dbarras@gmail.com.
Description: Store and Retrieve information from an .ini file
Download link: iniTutorial.zip (2.69KB)
Further comments/explanation:
.ini files are powerful and allow programmers to store data for their programs, but what if we could extend that power to saving game state data for our games. That's just what I'm going to show you how to do.
First you must have GameMaker. I suggest either 5.3a or 6.1 for this tutorial.
An .ini file has three parts.
- Section
- Key
- Value
A typical .ini file looks like the following.
[Window] would be a Section
heading is a Key
and ZeldaMaker is the value, in this case a string
In GameMaker, to write this value you would simply use this code
ini_open('dialog.ini');
ini_write_string('Window', 'heading', 'ZeldaMaker');
ini_close();
to read this value into your game you would have to assign it a variable, like this...
ini_open('dialog.ini');
heading = ini_read_string('Window', 'heading', '');
ini_close();
As you can see, .ini files are powerful, and very easy to read/write.
This showed you how to store data you had written, but what if you already had the value in your game, and wanted to write it to a Players Save file... you would use the following code.
ini_open('player1.zss');
ini_write_string('Player', 'Name', string(global.name));
ini_write_real('Player', 'HeartContainers', real(global.hc));
ini_close();
and voila! you have a save state file.
The file would look like this when written
[Player]
Name=Daniel
HeartContainers=5
Also, remember that .ini files HAVE TO reside in the same folder as your .exe file. So if you are storing them somewhere else, make sure they are moved/copied to your working_directory, before reading/writing.
I know what you're thinking... "But can't someone just open up your file and cheat"... yes!, but not if we include some kind of encryption/decryption.
There are plenty of encryption/decryption algorithms, as well as .dll files on the GameMaker forums.
If you have any questions on how to implement something like this, don't hesitate to email me at dbarras@gmail.com.