The INI tutorial


1.1 How to place
1.2 How to save a value from a counter to an INI file
1.3 How to save several values into the same group
1.4 How to load an INI value to a counter


1.1 How to place


To place an INI Object in your game, simply create a new INI object from the new object window. Then make a name for it. Do not write the whole patch, just the name og the file. For instance, TEST.ini. The file TEST.ini will be made in your windows folder next time you play the game.


1.2 How to save a value


First, you have to tell the program what GROUP it shall read from / write to.
Make this event:

* Start of level
: Set ini group to STATS

When you now play the level, the program sets the group to STATS. If this group is not in the INI file, it will be made.

You will not notice any changes in the game with just this EVENT, but you can look in your windows category and find the file called TEST.ini, and see that it contains a group called STATS.

This is displayed like this:

[STATS]


Now we will save a value. First, make a counter an give it a value. I give it the value 5.

Now, add this ACTION to the EVENT you allready have, so we can tell which item the value shall belong to:

: Set INI item to COUNTER VALUE 1

You can call the item everything you want. I called it COUNTER VALUE 1.

Now we will save the value of the counter into the INI file.

Right click under the INI icon and select Set value.
A new windows pops up. Here you can enter a value, but we wants to get the counter's value, so click the EDIT button, and then Retrieve data from an object. Now right click the Counter object and select Current value. Press OK.

Now the value of the counter will be saved into the INI file.

The whole Event will looks like this.

* Start of level
: Set INI group to STATS
: Set INI item to COUNTER VALUE 1
: Set INI value value (counter 1)


Run the level, and open the file. It will look like this:

[STATS]
COUNTER VALUE 1=5


1.3 How to save several values into the same group


Now we will add one more value to the ini file. We will still use the same counter.

We also want to save it into the same GROUP. But we want to do this when the player presses the SPACE button.

So, make this EVENT.

* Upon pressing Space bar
: Set value of counter 1 to 10.
: Set INI item to COUNTER VALUE 2
: Set INI value value (counter 1)

We didn't name the group, because that is allready set. But we had the change the item since we wanted to save it to another spot of the ini file. If else, the first value would just have been overwritten.

The INI file will now look like this:

[STATS]
COUNTER VALUE 1=5
COUNTER VALUE 2=10
he


1.4 How to load an INI value to a counter


Now make another application, or a new level in the same game, and place the same objects that we have used before into the level. Also, make a new counter. But this time you don't need to preset the counters' values.

We will now make the event that will make the INI ready to read from.

* Start of level
: Set INI group to STATS
: Set INI item to COUNTER VALUE 1

Now, we will load the first INI value into counter 1. To do this, we have to add a another action to the same event. Right click below the counter icon and select Set counter. A window will pop up. Select EDIT and Retrieve data from an object. Now right click the INI icon and select Get value. Press OK.

Test the level and you will see that the counter will change its value to 5.

To load the other value into the other counter, you have to add a new action to the event:

: Set INI item to COUNTER VALUE 2

The INI file will now read from this item. So do the same for the other counter as you did for the first one.

Test the level and you will see that the first counter is 5 and the other one is 10.

Here is the events in the right order:

* Start of level
: Set INI group to STATS
: Set INI item to COUNTER VALUE 1

: Set counter 1 to value if INI.

: Set INI item to COUNTER VALUE 2

: Set counter 2 to value if INI.


The order of the events are very important, and you shall therefore be very careful when trying to copy such events. Often you have to type all in manually and can't just copy the events.