Author Topic: Making vars out of .ini file  (Read 1279 times)

0 Members and 1 Guest are viewing this topic.

Offline Mighty

  • Camper
  • ***
  • Posts: 276
Making vars out of .ini file
« on: March 01, 2011, 10:24:25 am »
I got something like that:
Code: [Select]
const
  MYCONST = 3;

var
 MyArray: array[1..MYCONST] of integer;

Now I'd like to store settings in .ini file, is there any way i could do this making it  array[1..DATA_FROM_INI] of integer ?
Or is this simply impossible and i have to store settings as consts?
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID

Offline Falcon`

  • Flagrunner
  • ****
  • Posts: 792
  • A wanted lagger
Re: Making vars out of .ini file
« Reply #1 on: March 01, 2011, 10:26:02 am »
it is possible, but array should be dynamic, and you need to write some quite complicated functions for this
If you're not paying for something, you're not the customer; you're the product being sold.
- Andrew Lewis

Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Making vars out of .ini file
« Reply #2 on: March 01, 2011, 03:33:40 pm »
if you're not going to modify and save the settings on the fly, just use em as consts from inside the script imo. It's as easy to edit (both .ini and .pas are plain text -.-) and you'd save on HDD reads and lines of code.
Your only concern could be RAM usage (oh noez, the consts are going to be loaded in the RAM all the time!), but the whole script is stored in RAM anyway, including ini handling functions :L

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Making vars out of .ini file
« Reply #3 on: March 01, 2011, 08:52:21 pm »
@dnmr: lol ram usage shouldn't be that huge of a deal with it comes to non-huge configurations (what type of configuration would take enough ram usage to become of concern? :P)

@dnmr: ini files make it so the script can be easily configured by somebody who does not know anything about scripting (despite how easy it is to open up and edit constants :P)

Depending on your functionality, dynamic or static arrays may be more appropriate.
Depending on how your ini looks, and how you want the variables to look and be accessed, things could look differently. For example, you could load the whole ini: categorys, keys and values all; and then just create a search function that "index"es them by a category & key when you need a value (although this will also load unneeded values, or may cause issues if you do not check if required categories or keys are existing; also any conversions from string to another type would have to be redone every time. i do not suggest this idea).
I'm not going to go over all the possibilities you could set it up.

If I recall correctly, ReadINI has a memory leak, and should be avoided (until fixed). It may be more appropriate to create your own INI parsing functions to fetch the necessary information.

Offline Mighty

  • Camper
  • ***
  • Posts: 276
Re: Making vars out of .ini file
« Reply #4 on: March 02, 2011, 03:26:05 am »
Yeah i got my own INI function, but as suggested by dnmr, i left config in .pas file. Atm I'm not interested in spending hours on loads of lines which i would have tousands of problems with and probably still wouldn't understand fully :P

Thanks for help anyway, a bit new stuff acknowledged :P Maybe I'll come back to this sometime to get more info about how to actually do it, but for now consts seem to be enough :)
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID

Offline Polifen

  • Soldier
  • **
  • Posts: 127
Re: Making vars out of .ini file
« Reply #5 on: March 02, 2011, 04:26:52 am »
It should be enough to use dynamic array and just parse the .ini ( with your function, not with ReadINI which is buggy ) in OnActivateServer and use SetArrayLenght(my_array, StrToInt(value_from_ini));.

Offline Mighty

  • Camper
  • ***
  • Posts: 276
Re: Making vars out of .ini file
« Reply #6 on: March 02, 2011, 09:35:46 am »
It works ;) Thanks for that one, Poli :)
xFire: macmil        e-mail: macekmil@gmail.com
My scripts: Accuracy Script       Flashbang       Punishments GUID
            CatchMe Gamemod       AntiFake
            CW System             AntiFakeGUID