Adventure Game Studio | Forums

AGS Support => Modules & Plugins => Topic started by: Wyz on 18 Aug 2012, 13:35

Title: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Wyz on 18 Aug 2012, 13:35
IniFile2 1.0.0 (download: 3kb) (https://drive.google.com/open?id=19hCte-I5U8R4koS__Yjc25hgF1HbB9eq)
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!
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Construed on 18 Aug 2012, 22:41
As always, top notch stuff :D
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Miori on 12 Jan 2014, 13:03
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
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Wyz on 12 Jan 2014, 13:27
No problem, the links has been updated! :)
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Miori on 13 Jan 2014, 11:03
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
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Wyz on 13 Jan 2014, 21:09
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.  
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: RickJ on 14 Jan 2014, 01:16
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... 
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Miori on 14 Jan 2014, 11:11
Ah now I got it :D Thank you so much ^.^ And yeah, it IS really easy after all :)
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Cassiebsg on 24 Mar 2016, 14:53
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).
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Wyz on 06 Apr 2016, 12:50
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. :)
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Crimson Wizard on 06 Apr 2016, 14:44
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?
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Gurok on 06 Apr 2016, 15:39
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.
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Cassiebsg on 06 Apr 2016, 16:03
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.
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Crimson Wizard on 06 Apr 2016, 18:05
Cassie, you have buttons named Save and Load.
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Cassiebsg on 06 Apr 2016, 18:14
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. :-[
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: CrashPL on 23 Jun 2016, 12:45
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?
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Mehrdad on 23 Jun 2016, 13:11
Quote
404 Not Found

:( Can I ask for a reupload?

Here you are :
https://www.dropbox.com/s/ckkhhuim4zlcam4/IniFile2.zip?dl=0
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Crimson Wizard on 23 Jun 2016, 15:10
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.
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Crimson Wizard on 09 Nov 2017, 23:09
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 :).
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Wyz on 10 Nov 2017, 22:24
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