Author Topic: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files  (Read 2823 times)

Wyz

  • AGS Project Tracker Admins
  • anno 1986
    • I can help with making music
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
I've made a module that can read and write .ini files. This can be used to store configuration for a game regardless of savefiles. It is really easy to use and self documented. Type:
Code: Adventure Game Studio
  1. IniFile ini;
  2. ini. //(a list of possible functions will appear)
  3.  
When you are curious what a function does, simply select it and the auto-completer will tell you what it does.

I just noticed there is a module that does the same thing with the exact same name which I was unaware of (heck I was pretty sure I checked before I made this). The module is part of a game module I'm making for someone and if I knew there was already one it could have saved me some time... This version is made for AGS 3.x and the old one for 2.x so I thought it might still be a wise idea to publish it.

The module uses the ini format which is commonly used by windows applications. It looks like this:
Code: INI
  1. [section1]
  2. key1=value1
  3. ; comments can appear on empty lines, preceded by a semicolon
  4. key2 = value2
  5. key3 =value3
  6.  
  7. [section2]
  8. number1=42
  9. boolean1=1
  10.  

Special characters in key and section names are not supported and spaces in values at the left and right will be trimmed. That is basically it.

I hope that it will be useful to someone. Any questions, comments or requests: feel free to post them here!
« Last Edit: 10 Nov 2017, 22:20 by Wyz »
Life is like an adventure without the pixel hunts.

Construed

  • The fear of the LORD is the beginning of wisdom.
    • I can help with AGS tutoring
    •  
    • I can help with animation
    •  
    • I can help with backgrounds
    •  
    • I can help with characters
    •  
    • I can help with making music
    •  
    • I can help with play testing
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
As always, top notch stuff :D
I felt sorry for myself because I had no shoes.
Then I met the man with no feet.

The download is no longer available i'm afraid, but i'm very interested in your module. Could you please post an new downloadlink? Pleeease :-D

Wyz

  • AGS Project Tracker Admins
  • anno 1986
    • I can help with making music
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
No problem, the links has been updated! :)
Life is like an adventure without the pixel hunts.

Ah thank you very much :D

edit: Ahm... sorry, you said it is easy to use, but maybe i'm the sort of people who need an explanation for idiots XD Could you just give me an example, so I can see how it works? :)

For example... save the string variable TEST to ini.ini, load it and show the saved string in a label? That would make it understandable for me, i think. Examples are more useful to me than long explanations XD
« Last Edit: 13 Jan 2014, 11:42 by Miori »

Wyz

  • AGS Project Tracker Admins
  • anno 1986
    • I can help with making music
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Sure :)

Here is an example room script. It will load the ini file and print some values from it and then it will put some values in the ini file and save it again. Let me know if you have more questions :)

Code: Adventure Game Studio
  1. IniFile ini;
  2.  
  3. function LoadIni()
  4. {
  5.   ini.Load("ini.ini");
  6.  
  7.   String key1 = ini.Read("section1", "key1", "default");
  8.   int key2 = ini.ReadInt("section1", "key2", 0);
  9.   float key3 = ini.ReadFloat("section1", "key3", 0.0);
  10.   bool key4 = ini.ReadBool("section1", "key4", false);
  11.  
  12.   Display("key1 = %s", key1);
  13.   Display("key2 = %d", key2);
  14.   Display("key3 = %f", key3);
  15.   if (key4)
  16.     Display("key4 = true");
  17.   else
  18.     Display("key4 = false");
  19. }
  20.  
  21. function SaveIni()
  22. {
  23.   ini.Write("section1", "key1", "Test");
  24.   ini.WriteInt("section1", "key2", 1234);
  25.   ini.WriteFloat("section1", "key3", 12.34);
  26.   ini.WriteBool("section1", "key4", true);
  27.  
  28.   ini.Save("ini.ini");
  29. }
  30.  
  31. function room_AfterFadeIn()
  32. {
  33.   LoadIni();
  34.   SaveIni();
  35. }
  36.  
Life is like an adventure without the pixel hunts.

RickJ

  • fix'n one thing and break'n two ...
    • I can help with scripting
    •  
    • I can help with story design
    •  
Wow!  What a blast from the past grin:

I wrote the old version of the module and and think it was probably the very first bit of code to use the AGS module system.  I'm glad there is a newer version ... it's something that need to be done for a long time.  Btw, I don't have a problem if anyone wants unify both versions.  The module guidelines describe a method of keeping module versions and dependencies straight (I'm sure Wyz is already knows this).  Anyway Wyz, nice work... 

Ah now I got it :D Thank you so much ^.^ And yeah, it IS really easy after all :)

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
Just wish to thank you for this module!
Took me a while to figure out how to set it up and make it do all I wanted, but my "skills" finally caught up and it's now working perfectly. (nod)

I did had to change Load and Save to IniLoad and IniSave, as AGS was complaining that Load and Save were already assigned (am using 3.4.0.6 Beta).
There are those who believe that life here began out there...

Wyz

  • AGS Project Tracker Admins
  • anno 1986
    • I can help with making music
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Thanks for your feedback, I appreciate it! :)

Hmmm the naming clash should not occur; I saw someone else with a similar problem so I'm going to look into it. :)
Life is like an adventure without the pixel hunts.

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
This resembles the long-existing problem in AGS: if you have a function in global namespace, you cannot have struct function of same name.
http://www.adventuregamestudio.co.uk/forums/index.php?issue=361.0

An interesting thing is, though, that this error seemed to have been fixed in 3.4.0.6. At least some script examples of similar nature work.
We might need to investigate this further.

Is it possible to see your project, Cassiebsg?
« Last Edit: 06 Apr 2016, 15:01 by Crimson Wizard »

Gurok

  • Rottwheelers
  • When life hands you lemons, combine them with the mop
    • I can help with AGS tutoring
    •  
    • Best Innovation Award Winner 2016, for improving and extending the AGS scripting language
    •  
    • I can help with proof reading
    •  
    • I can help with scripting
    •  
  • Gurok worked on a game that was nominated for an AGS Award!Gurok worked on a game that won an AGS Award!
Regarding Cassiebsg's error, you'll still get this in 3.4.0.6 if you define a GUI called Load. I am not sure, but I suspect that this might be Cassiebsg's situation.

My commit addressed conflicting global function names, but it seems GUIs (and perhaps other editor-defined objects) cause similar namespace issues. I would be happy to look into this, pending CW seeing the project or Cassiebsg confirming that's the problem.
« Last Edit: 06 Apr 2016, 15:41 by Gurok »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
I was going to say Gurok was right, but no. My GUIs are called gSaveGUI and gLoadGUI after checking... and I'm using 3.4.0.6.
However, if I type "sav" to get the tooltip to show up, I can see a Save with a blue box on the list. Same with load...

I'll zip a copy of my project and send you the url CW.
There are those who believe that life here began out there...

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
Cassie, you have buttons named Save and Load.

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
LOL, I do? Ack...
that's happens when you make a GUI before you realize that you should name your buttons "btn..."... (roll) I thought I had changed all the buttons... guess not. (roll)
sorry. :-[
There are those who believe that life here began out there...

CrashPL

  • The dinosaur guy
    • I can help with AGS tutoring
    •  
    • I can help with animation
    •  
    • I can help with characters
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
  • CrashPL worked on a game that was nominated for an AGS Award!
Quote
404 Not Found

:( Can I ask for a reupload?

Btw does this module works with Windows only, or can I use it on Linux/Mac as well?


Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
Btw does this module works with Windows only, or can I use it on Linux/Mac as well?

I believe it should work anywhere, because
a) Module is a script, and every all AGS script should work regardless of where you run it (assuming the port is done correctly).
b) INI file is not system specific, it is just format of text file, like JSON or XML.
« Last Edit: 23 Jun 2016, 15:12 by Crimson Wizard »

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
Sorry for necroposting, but I just decided to give this topic a bump. This module just saved me a ton of time. Needed to implement a text data file for my game, and it took 15 minutes to do with this module :).
« Last Edit: 10 Nov 2017, 09:43 by Crimson Wizard »

Wyz

  • AGS Project Tracker Admins
  • anno 1986
    • I can help with making music
    •  
    • I can help with story design
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
    • I can help with web design
    •  
Thanks! You're welcome CW! :-D

I've fixed the link in the first post btw. Still a ton of broken links out there I guess. :D
Life is like an adventure without the pixel hunts.