Jump to content

OBSE - Does anyone know how to read an ini file into an array?


Recommended Posts

I want to use an ini/text file for a list of item names to check against... one name per line.

 

So does anyone here know how to read a file like this into an array that can then be scanned to compare with items in a container/player inventory...

 

I've searched but can't find anything :(

 

 

Link to comment
Share on other sites

Pluggy (an OBSE extension) provides functions to read and write an INI file

 

This article gives you a detailed description on how to do it.

 

If you don't need to write data back into the text file, an alternative is to use RunBatchScript, but I don't know if there is a tutorial on how to use it. This article has a section comparing both methods.

Edited by QQuix
Link to comment
Share on other sites

Thanks for you quick reply QQuix :smile:

 

The sample code looks to be far more complex than anything I need to do but I think the bit I need from it is just...

let psFile     := createstring -1 0 1 1let psSep      := createstring -1 "|" 1 1let psText     := createstring -1 0 1 1let psFileText := createstring -1 0 1 1;=== Read file ===setString psFile  $sFile    FileToString psFile psFileText  let len := StringLen psFileText   StringRep -1310 psSep psFileText 1 len 0 1   ; Replace LFCR with "|"

Then I think I can just use the psFileText string to compare to ???

I think I can skip the to array bit for what I want it for.

Edited by The-Wanderer
Link to comment
Share on other sites

True. You may just use the IniRead... functions as in the "Introduction to Pluggy INI Files" example

 

Assuming you just need to read a list of string values, you may create an INI file like this

[MySection]
1=String1
2=String2
3=String3

And use the IniReadString function in a loop in order to read all lines

Supposing the number of entries in unknown, you may use the default value parameter to detect the end of the list.

Link to comment
Share on other sites

Well, I for one would "initialize" the array inside the mod's script, and then use RunBatchScript to load in an ObScript source containing the OBSE function calls used to populate it.

 

You can put the entire array into the external file loaded in via RunBatchScript, but I think in order to use it inside your mod you will have to put at least the declaration and initialization part into your script itself somewhere.

 

I'm not exactly sure though how OBSE functions and stuff will work when parsed through RunBatchScript, but going by my limited knowledge gained in its use in scripts of mine over the last months, I'm going to assume it 'should' work.

Link to comment
Share on other sites

Thanks for the input DraketheDragon :)

 

But... I think what I'm trying to do is a bit different... the file should not contain a list of functions... which is what all the scripts I've looked at so far do with it...

I want a dynamic list (unknown length) of just names that can then be read in on the fly and used to compare with other items names in a script

 

The file should be something like

 

[Omit]

item1

item2

..

itemX

 

[include]

item1

item2

item3

..

itemX

 

 

There is a Pluggy function "FileToString <filename> <outstring>" which I thought would give me the starting point from which I can then parse it to an array... but I can't even get it to read the file ???

Link to comment
Share on other sites

I have tried with various combinations of below...

But it seems it is not even recognising the file name ???

 

string_var sFile

or

Long sFile (which is how one example shows it)

 

then

 

set sFile to CreateString -1 "test.ini"

or

let sFile := CreateString -1 "test.ini"

 

 

I guess I should try just..

set sFile to "test.ini"

or

let sFile := "test.ini"

 

 

{Edit}

hmm... neither of them seem to work either ???

sFile appears to remains empty :(

Edited by The-Wanderer
Link to comment
Share on other sites

"set sFile to CreateString -1 "test.ini"" should work

 

Check if

  • sFile is declared as long (all Pluggy variables mus be Long)
  • The file is in the right folder: ... \My Games\Oblivion\Pluggy\User Files, where '...' is the same as in ...\My Games\Oblivion\Saves"
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...