View Full Version : All about ini Files

Da 0wner
03-26-2008, 04:45 AM
Today we are going to learn about ini files. There are 4 commands.


I am going to explain how to use them.

INI files are setup like this



Etc. But of course you always want antirandoms/antiban.

So to Write to an INI file ex Change UseAntiban to true you would do this

WriteINI('Settings', 'UseAntiban', 'True', AppPath + 'Settings.ini');

The 1st string is the section ie where it says [Settings].
The 2nd string is the subsection where it says UseRandoms=True and
The 3rd string is what to change it to.
The 4th string is the file path. AppPath is where scar is stored and the file name would be Settings.ini

To get whats written there you can do this

ExampleString := ReadINI('Settings', 'UseAntiban', AppPath + 'Settings.ini'));

That would read whats written in the file. ie it would return 'False'.

Now about SaveSetting. That saves a setting to the main SCARSettings ini file.

All you need to do for that is

SaveSetting('Settings', 'UseAntiBan', 'False');

That saves a setting in section Settings and subsection Useantiban to 'false'.

To load setting you can do this

ExampleString := LoadSetting('Settings', 'UseAntiBan');

That would store the setting in the examplestring string.

That's all there is to it to my short tut ;).

If you have any additional questions please post and i will answer.

As always, don't forget to rep and rate this excellent!

03-26-2008, 05:02 AM
I requested a tut like this! Thanks, I'll look more closely into this whenever I can script (NOT on a iMac G3..)

skilld u
03-26-2008, 05:03 AM
looks nice, i wanted one of these.

Iron Man
03-26-2008, 08:02 AM
Very nice tutorial. When I get to this part on my form, I'll Re-Read this.

Dan Cardin
03-26-2008, 11:10 AM
i use scriptpath instead of apppath, but when i try and read an ini/use fileexists then for some reason my file isnt found. Could that be because i am running this from a usb? because if i just give the actual path(and ive checked to make sure they're the same) it works fine.

p.s. no offense but you've written like 5 tuts in 2 days, and they all seem kind of...incomplete(except the first one you made). I think you should spent a little more time on them :(

03-26-2008, 01:47 PM
very very nice tut man:D
now i finally understand a bit of it ^^
nice done;)

03-26-2008, 04:55 PM
A better example would have been saving and loading players, but never mind. I really wouldn't expect to find this tut by itself anyway as ini files are to short to really have one tut for them, unless you wanted to explore their uses much more. Also, I would say it's generally better to save in ScriptPath as then the script runner will actually be able to see it and delete if they don't want to use your script anymore. Lastly, ini's actually work best with forms as it allows you to save submitted information and recall them in a procedure - if you don;t get what I mean, I think my ini DeclarePlayer's saver and loader is in the Tes Corner somewhere.

Da 0wner
03-26-2008, 10:09 PM
Mixter i got one too ;) also gonna add a thing like srl members yea i was writing these way late near 2-5am. and @Dan You don't need filexists for ini files it creates them automatically. Unless you want to detect where it is and set path to that etc.

Dan Cardin
03-27-2008, 12:55 AM
no, im doing something like
if not fileexists(ini) then

but even though the file exists it still acts as if it isnt

Da 0wner
03-28-2008, 06:01 AM
you don't need fileexists it already creates file and writes if it dosent if it does it just writes.

Dan Cardin
03-28-2008, 10:58 AM
thats not what im saying :p. if the file isnt written then i need to pop up my mini form so they can fill their preferences in so that i can write the ini. If its already written then i dont plan on popping that form up.

03-28-2008, 04:39 PM
Have you remembered to include the path to the ini file (so it's ScriptPath+'inifile.ini', rather than just 'inifile.ini')? If not, then it probably would've given you an error, though I think it would just try to check it from your default hard drive (so 'C:\inifile.ini'), which would cause it to always return false as that file doesn't exist, but you do write the ini file somewhere else, though I'll experiment a bit to see.
Edit: Played with it and it'll always run it (without ScriptPath), though it looks like if you don't have ScriptPath, then it adds it automatically. It worked fine, had a Writeln setup with booltostr, and I know the files I tested existed when it said true and didn't when it said false, so it may be that you're not looking for the right file or something.

Dan Cardin
03-28-2008, 06:22 PM
lol i fixed it...i made a silly mistake. Now my problem is from your version checking tut on the other site :p. (you going to make the other one any time soon? jw)

03-28-2008, 06:28 PM
I would make more, but I made one here and it got shunned, so I've been put off continuing it, though maybe I will just for you ;)
And if it's the same error as before (from my tut), then just add a post variable and it *should* fix it, otherwise steal the code from my tut here as I double-checked it all.

10-19-2008, 11:39 AM

i have been wanting to make the form in ucb store the settings and now i know
ty and wd rep++


10-19-2008, 02:43 PM

i have been wanting to make the form in ucb store the settings and now i know
ty and wd rep++

[10:42:17] <mixster> GoF`: http://www.srl-forums.com/forum/ss08-all-ini-p484670.html <- Shuttleu gravedugged! Must be flamed!


10-19-2008, 02:54 PM
nooo... i didnt gravedig i just congradulated him on doing soo well...

why did you put GoF ?


Da 0wner
10-20-2008, 12:44 AM
Gravedigging is when you post something useless on an old tutorial.

My belief about gravdigging is that if you post a constructive or useful post on an old thread than there is nothing negative about it. Although if you post something useless like 'gj nice tut' or 'ty helped' then it is negative. So I do think that you gravedug shuttle. But, if you added something like 'how do i do x?' or 'you should also note in ur top that ...x...' then it wouldn't be considered gravedigging (by me).

I don't see why we look negatively upon posting on old threads. We should only consider it negative if there is no useful information whatsoever.

And hy, if you accuse him of gravedigging and do it within the topic then you are also contributing to the gravedigging, thus being as bad as what he did. You should report or resolve it with PMs.

Ha. Kyle.