Inis for Noobs and Experts
Author: | Assault Andy
|
Submitted: | 4th May, 2003
|
Views: | 9786
| Rated: |
|
|
Yet another Ini Article, Hopefully I include something new or make mine easier than the average. I have included some noob things and some expert things (at the very bottom.) But it's mainly noob stuff.
What's an Ini?
An .ini is a file type, it is used for storing information so that you can save/load your data even when you shut your computer off. They are essential to all rpgs, adventure, anything that you are planning to continue next time you start (unless you use a Array but we will leave that for another article ). Later on in this article i will write a glossary for all (or most) of the ini's functions.
Let's roll - Saving
I will be using Ini Plus because its a hell of alot easier than the normal ini, way quicker, and isn't any worse. Get it from:
www.pluginx.com
Except I think they are down at the moment.
Righty-O open up TGF/MMF and let's get started. Insert an ini plus object and set the ini file to use as mygame.ini, next place a counter and a button. Go to the event editor and create a new event:
If button pressed then Add 1 to counter and,
set current file to Appdrive$ + Appdir$ + Gamenamehere.ini
set current group to Times Clicked
set current item to button
set current value to (value of counter)
What does it all mean?
Let's take it step by step shall we?
I think you all know what pressing the button does (if you don't this is to advanced for you)
set current file to Appdrive$ + Appdir$ + Gamenamehere.ini >>> This sets the data to be saved wherever the file is, so if your .cca is installed in C:\mmf\ini.cca then it will save it there as gamenamehere.ini Glossary at the bottom for complete definition of Appdrive and dir.
set current group to Times Clicked >>> This sets the group to Times clicked
set current item to button >>> Each group can only hold one value or string so inside it we create an item called button we can have as many of these as we need inside a group.
set current value to (value of counter) >>> This is pretty self explanitory, but what it does is it sets the value inside the item button to what ever thevalue of the counter is.
Loading
One of the better features of Ini plus is the Save/Load feature. It's loading is alot faster and easier than the normal Ini object. For example, if we wanted to load the value from the ini and set that value to a counter at the start of the level we could do this:
Start of Frame then Set counter to groupitem( Ini Plus, Times Clicked, Button )
This would get the value in the group Times Clicked and the Item Button and set that value to the counter.
What else can I do?
Inis are very powerfull not only can you save values but you can also save strings, this is usefull for mission objectives and questlogs. Saving strings is exactly the same as saving values all you have to do is change set value to set string (remeber each item can have one string and one value.) You can also save and load the position of an object, using the save and load position button.
Glossary Of Terms
Ini - I've only been talking about it the whole time.
Set File - Set the filename of the Ini and it's location.
Set Group - Sets the group in an ini which can hold items.
Set Item - Sets the item name.
Set Value - Sets the value inside an item. (If you have not specified an item it will just save it in the group)
Set String - Same as above.(With strings)
Save/Load Object Pos Saves/Loads the Position of an object.
Appdrive$ - Current drive where the .cca/.exe is.
Appdir$ - Currect directory where the .cca/.exe is.
Encrypt/Decrypt - Coding a file so others can't edit it.
Advanced Stuff
Creating Users
You can use inis to create users here is some code to do it:
Firstly create a combo object(dropdown),an ini plus ,a counter and a button (put em neatly). Set the text on the button to add one
Go to the event editor and create a new event:
start of frame - set file to appdrive$ + appdir$ + users.ini, disable add one, do loop create user (iniplus, users, number)
and another:
Key enter pressed - Set group to value(counter 2),set item to name, set string to Edit text$( Combo Box ), enable add one,set counter to value from iniplus - (value(counter 2), score), Edit text$( Combo Box ), add one to counter 2, Set group to users, set item to number,set value to counter2.
2nd last one:
Button add one pressed - Add one to counter, set ini value to value of counter.
Last one:
on loop create user - add a line(combo), groupitem$( Ini Plus, Str$ ( LoopIndex ( Create user ) ), Name ).
That took a while!
This would not work if you had thousands of accounts, because an Ini can only hold 64kb of data . I am using a simliar teqnique to this in my upcoming mmorpg with Pkoed except that I am creating a new Ini for every player because eventually an Ini file would run out of space.
Looking Professional
A good idea if you are making a game with multiple users or a game with customizable options is to have an Ini that can be used to save these temporarily. Also for the options you might want to be able to save them as schemes, eg. crazy which might have unlimited ammo and all guns and realistic which might have limited ammo and pistols and snipers.
Encrypting and Decrypting
This is easyily acomplished, all you have to do is get an encryption object of some sort (there are tons around) set the file to encrypt when you save, and then set it to decrypt when you load. Simple, but here's a short example:
Save Pressed - decrypt C:\data.ini with encyption value 10, (save data), encrypt C:\data.ini with encyption value 10.
Load Pressed - decrypt C:\data.ini with encyption value 10, (load data), encrypt C:\data.ini with encyption value 10.
We encrpyt it everytime we save and load *not just at the start and end of the game because if they ran the game and it was programmed to decrypt at the start of the game then while the game was running they could edit it.
THE END!
Well that's all folks, it was a damn long article and I think a good one at that. I hope you have all learnt something.
-Assault Andy (12, CCsoft)
|
|
|