Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: Wyz on Sat 18/08/2012 13:35:49

Title: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Wyz on Sat 18/08/2012 13:35:49
IniFile2 1.0.0 (download: 3kb) (https://drive.google.com/file/d/19hCte-I5U8R4koS__Yjc25hgF1HbB9eq/view?usp=sharing)
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 (AGS) Select

IniFile ini;
ini. //(a list of possible functions will appear)

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) Select

[section1]
key1=value1
; comments can appear on empty lines, preceded by a semicolon
key2 = value2
key3 =value3

[section2]
number1=42
boolean1=1


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 Sat 18/08/2012 22:41:38
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 Sun 12/01/2014 13:03:49
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 Sun 12/01/2014 13:27:37
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 Mon 13/01/2014 11:03:49
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 Mon 13/01/2014 21:09:37
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 (ags) Select

IniFile ini;

function LoadIni()
{
  ini.Load("ini.ini");
 
  String key1 = ini.Read("section1", "key1", "default");
  int key2 = ini.ReadInt("section1", "key2", 0);
  float key3 = ini.ReadFloat("section1", "key3", 0.0);
  bool key4 = ini.ReadBool("section1", "key4", false);
 
  Display("key1 = %s", key1);
  Display("key2 = %d", key2);
  Display("key3 = %f", key3);
  if (key4)
    Display("key4 = true");
  else
    Display("key4 = false");
}

function SaveIni()
{
  ini.Write("section1", "key1", "Test");
  ini.WriteInt("section1", "key2", 1234);
  ini.WriteFloat("section1", "key3", 12.34);
  ini.WriteBool("section1", "key4", true);
 
  ini.Save("ini.ini");
}

function room_AfterFadeIn()
{
  LoadIni();
  SaveIni();
}
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: RickJ on Tue 14/01/2014 01:16:56
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 Tue 14/01/2014 11:11:46
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 Thu 24/03/2016 14:53:13
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 Wed 06/04/2016 12:50:04
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 Wed 06/04/2016 14:44:00
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 Wed 06/04/2016 15:39:01
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 Wed 06/04/2016 16:03:15
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 Wed 06/04/2016 18:05:51
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 Wed 06/04/2016 18:14:44
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 Thu 23/06/2016 12:45:23
Quote404 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 Thu 23/06/2016 13:11:08
Quote from: CrashPL on Thu 23/06/2016 12:45:23
Quote404 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 Thu 23/06/2016 15:10:58
Quote from: CrashPL on Thu 23/06/2016 12:45:23
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 Thu 09/11/2017 23:09:23
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 Fri 10/11/2017 22:24:29
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
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Dave Gilbert on Thu 04/04/2024 15:49:56
Hey! I just discovered this module and I can't believe I didn't find it earlier. I've been playing around with it and it works GREAT. However, I am wondering precisely where it saves the file? I am saving it as "skies.ini" but I can't find it anywhere on my hard drive. Searching for the file reveals nothing. I can load, save and read the data just fine but I have no idea where the file is actually located. :)
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Crimson Wizard on Thu 04/04/2024 16:54:26
Quote from: Dave Gilbert on Thu 04/04/2024 15:49:56However, I am wondering precisely where it saves the file? I am saving it as "skies.ini" but I can't find it anywhere on my hard drive. Searching for the file reveals nothing. I can load, save and read the data just fine but I have no idea where the file is actually located. :)

The module is not responsible for the file paths, it simply uses engine's functions for opening a file.
The file paths are explained here, for the File.Open command:
https://adventuregamestudio.github.io/ags-manual/File.html#fileopen

see " location tags " and all the warnings about their use below.
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Dave Gilbert on Thu 04/04/2024 17:19:38
Sorry. I didn't word that right. I know how to set the file location, but I don't see it on my hard drive. I set it to the save folder, the install folder, a random folder on my hard drive, it just doesn't appear when I navigate to the folder. The game is able to load, save, and read from it just fine, but I can't see the actual file. So I'm very confused!
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Cassiebsg on Thu 04/04/2024 17:26:44
Maybe your OS is set to hide ini files?
Try and save it under a different name extension, like .txt. It's just a plain text file anyway (as far as I remember).
Title: Re: MODULE: IniFile2 1.0.0 (AGS 3.x) - Read and write configuration to files
Post by: Dave Gilbert on Thu 04/04/2024 17:30:27
Aha. That did it. Thank you!