Author Topic: INI Functions  (Read 6437 times)

0 Members and 1 Guest are viewing this topic.

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
INI Functions
« on: November 20, 2007, 11:46:56 am »
Script Name: INI Functions
Script Description: Has functions that parses INI files and lets you read/save/modify/add/delete entries.
Original Author(s): PerroAZUL
Core Version: 2.6.3
Requirements: xSplit

I made some INI functions that some may find usefull, so I shall share it with the ladies.

It consists of this functions:

Code: [Select]
function iniLoad(FileName: string): TINIFile;

procedure iniSave(FileName: string; var iniFile: TINIFile);

function iniGetValue(var iniFile: TINIFile; section, key, errorResult: string): string;

procedure iniSetValue(var iniFile: TINIFile; section, key, value: string);

procedure iniDeleteSection(var iniFile: TINIFile; section: string);

procedure iniDeleteKey(var iniFile: TINIFile; section, key: string);

procedure iniWrite(FileName, section, key, value: string);

I don't think they need any more explanation than what a TINIFile is:

Code: [Select]
type TSection = record
Name: string;
Keys: array of string;
end;

type TINIFile = record
Sections: array of TSection;
end;

The section names are case insensitive. I might add some other functions later, like iniFindSection, which would return the section index in TINIFile.Sections array, and iniFindKey, which would do the same but for TSection.Keys. Not a big deal but could save some writing.

If you happen to find any bug Report!.


I'll add an example:
Code: [Select]
var ini: TINIFile;

ini := iniLoad('soldat.ini');
WriteLn(iniGetValue(ini, 'network', 'Greeting_Message', ''));
iniSetValue(ini, 'network', 'Greeting_Message', 'Hello!');
iniSetValue(ini, 'custom', 'var', 'x'); // this will add the section [custom] with "var=x"
iniSetValue(ini, 'network', 'lala', '1'); // this will add "lala=1" in [NETWORK]
iniSave('soldat.ini', ini); // must call to save changes

Edit: Found a stupid bug, fixed it.
« Last Edit: November 21, 2007, 12:18:46 pm by PerroAZUL »
urraka

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: INI Functions
« Reply #1 on: November 20, 2007, 08:52:27 pm »
are we allowed to fix misspellings in the comments? :)

nice script

btw, you should make a "LastDelete: array[1..*your undoamount const*]" variable and whenever you delete a section or a key, it's value would be saved in the next open spot wait nevermind, person could just not save the ini, or you could make something to say "Cannot overwrite game INIs, please choose another name"
« Last Edit: November 20, 2007, 09:03:47 pm by Kavukamari »
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: INI Functions
« Reply #2 on: November 20, 2007, 08:56:40 pm »
What misspellings? You must be crazy!
urraka

Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: INI Functions
« Reply #3 on: November 20, 2007, 09:05:37 pm »
Quote
//---   You may use or modify this script to satisfy whatever
//---   needs or feels your ass.
//---   This commented lines must remain untouched.
//---   If you somehow are able to make money with this code
//---   or part of it, you will be cought by PerroMAFIA and
//---   your ass will be raped.

(and lol, you said "ass" many many times)

and I might be crazy, I'm not sure «_« »_»
« Last Edit: November 20, 2007, 09:08:37 pm by Kavukamari »
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: INI Functions
« Reply #4 on: November 20, 2007, 09:11:10 pm »
Well, the mistakes are already there, and it says I can't touch those lines.
urraka


Offline Kavukamari

  • Camper
  • ***
  • Posts: 435
  • 3.14159265358979, mmm... pi
Re: INI Functions
« Reply #6 on: November 27, 2007, 12:50:15 pm »
Sticky: Release Post Template
Sticky: Release Post Template
Sticky: Release Post Template
Sticky: Release Post Template
Sticky: Release Post Template

yeah, I was thinking that too... (except maybe with less repitition) I didn't have any trouble placing/using the script, but other ppl might
"Be mindful of fame, show a mighty courage, watch against foes. Nor shalt thou lack what thou desirest, if with thy life thou hast comest out from that heroic task."

Offline pinOi32

  • Camper
  • ***
  • Posts: 339
  • "Bravo kid's bad day"
    • Newgrounds
Re: INI Functions
« Reply #7 on: December 24, 2007, 02:28:05 pm »
umm I dont understand what this does.
Pls use my amazing interface:
http://forums.soldat.pl/index.php?topic=27584


I WIN!!

WHY MY KARMA SUCK??

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: INI Functions
« Reply #8 on: December 24, 2007, 06:20:01 pm »
umm I dont understand what this does.

It doesn't do anything, it's just a bunch of functions that you might find usefull if you make a script that has to save/load information.
urraka

Offline LORD KILLA

  • Camper
  • ***
  • Posts: 254
  • Happie
Re: INI Functions
« Reply #9 on: December 21, 2008, 10:01:58 am »
Sorry I take this back of the past, but:

I tried to start a server with my script

the code:
Code: [Select]
function OnCommand(ID: Byte; Text: string): boolean;
begin

var
ini: TINIFile;

  if (GetPiece(Text, ' ',1) = '/editwep') then begin
  iniSetValue(ini, GetPiece (Text,' ',3), GetPiece (Text,' ',4), GetPiece (Text,' ',5));
  iniSave(GetPiece (Text,' ',2), ini); // must call to save changes
  end;

  if (GetPiece(Text, ' ', 1) = '/dis') then begin
  SetWeaponActive(0, GetPiece(Text,' ', 2), false);
  end;

  if (GetPiece(Text, ' ', 1) = '/en') then begin
  SetWeaponActive(0, GetPiece(Text,' ', 2), true);
  end;

  if (GetPiece(Text, ' ', 1) = '/disID') then begin
  SetWeaponActive(GetPiece(Text,' ',2),GetPiece(Text,' ',3), false);
  end;

  if (GetPiece(Text, ' ', 1) = '/enID') then begin
  SetWeaponActive(GetPiece(Text,' ',2),GetPiece(Text,' ',3), true);
  end;

  Result := false; // Return true if you want to ignore the command typed.
end;

It should enable to edit [edit/enadle/disable/enable for a special player/disable for a special player] weapons

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: INI Functions
« Reply #10 on: December 24, 2008, 06:16:31 pm »
You have to use iniLoad before using the other functions...

Code: [Select]
function OnCommand(ID: Byte; Text: string): boolean;
var
   ini: TINIFile;
begin

  if (GetPiece(Text, ' ',1) = '/editwep') then begin
  ini := iniLoad('YOURINI.INI');
  iniSetValue(ini, GetPiece (Text,' ',3), GetPiece (Text,' ',4), GetPiece (Text,' ',5));
  iniSave(GetPiece (Text,' ',2), ini); // must call to save changes
  end;

You have the 'var' and 'begin' messed up too, i think.
urraka

Offline rayanaga

  • Soldier
  • **
  • Posts: 143
  • ~Fur flying~
    • Kryonex
Re: INI Functions
« Reply #11 on: December 25, 2008, 12:22:30 am »
Hmm. Pretty nice and handy INI functions. Sure will make lives a lot easier.
[kY] Kryonex - Your local zombie fanatics.
http://www.kryonex.com/

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: INI Functions
« Reply #12 on: July 09, 2010, 07:39:44 pm »
i apologise for the bump, but do these functions require a begin and end for each in the script before using?

for example:
Code: (pascal) [Select]

procedure iniWrite(FileName, section, key, value: string);
begin
end;

function Oncommand..etc
begin
if Text = '/save' then Iniwrite('myfile.ini', 'profits', 'cash', inttostr(Tcash))
end;

is the begin and end all it needs before using or do i need some more code between the begin and end

please dont flame me, i dont see any point in starting a new topic just to ask about an older topic


check out my server! click here

If at first you don't succeed, Improvise! :D

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: INI Functions
« Reply #13 on: July 09, 2010, 10:22:32 pm »
You need to download the attached ini.pas script, which has the actual code for the functions in it.

Copy the functions you want to use into your script, then you can call them like any other function.
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: INI Functions
« Reply #14 on: July 09, 2010, 10:25:41 pm »
many thanks :) didnt notice the attachment

From: July 10, 2010, 10:28:27 pm
found a bug

what var type is xsplit supposed to be in IniLoad? its not defined
« Last Edit: July 10, 2010, 10:30:19 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: INI Functions
« Reply #15 on: July 11, 2010, 03:58:13 am »
It's alright how it is, just use it.

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: INI Functions
« Reply #16 on: July 11, 2010, 01:18:45 pm »
how? this is why im saying it not defined:

Code: [Select]
unknown identifier "xsplit"

how can i "use" it when its erroring?

whats the code for xsplit?
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Zapper

  • Major(1)
  • Posts: 31
Re: INI Functions
« Reply #17 on: July 11, 2010, 02:26:41 pm »
Ouch, auch, google can eat ya!
http://tinyurl.com/2azm5jm

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: INI Functions
« Reply #18 on: July 11, 2010, 06:49:56 pm »
The xsplit code is in the attached pas file. You will need to copy that over too.
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: INI Functions
« Reply #19 on: July 11, 2010, 07:46:18 pm »
nope, i copied the whole script, and ive even looked at it, there is NO "procedure/function xsplit();" (has anyone even tried compiling the attached file? see below) all i see is
Code: [Select]
xsplit:= (whatever it was) theres no xsplit in vars, neither is there a function or procedure for it before it is used, as a result:
the ini.pas fails to compile for the exact problem im having

Code: [Select]
inifunctions -> [Error] (16:11): Unknown identifier 'xsplit'

so can someone plz post the code for the xsplit function/procedure whatever it is?

has anyone successfully compiled the attached script? if so then why the the hell is my compiler being a douche?
« Last Edit: July 11, 2010, 08:01:41 pm by frosty »
check out my server! click here

If at first you don't succeed, Improvise! :D