TheWanderer001 Posted March 3, 2015 Share Posted March 3, 2015 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 More sharing options...
QQuix Posted March 3, 2015 Share Posted March 3, 2015 (edited) 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 March 3, 2015 by QQuix Link to comment Share on other sites More sharing options...
TheWanderer001 Posted March 3, 2015 Author Share Posted March 3, 2015 (edited) 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 March 3, 2015 by The-Wanderer Link to comment Share on other sites More sharing options...
QQuix Posted March 3, 2015 Share Posted March 3, 2015 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=String3And use the IniReadString function in a loop in order to read all linesSupposing 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 More sharing options...
TheWanderer001 Posted March 3, 2015 Author Share Posted March 3, 2015 Thanks I'm going to have to play around a bit with this once I get home tonight...I'll come back and post my findings... in case anyone else finds it useful/interesting. Link to comment Share on other sites More sharing options...
TheWanderer001 Posted March 3, 2015 Author Share Posted March 3, 2015 Hmm... given this a little more thought and realize... no I can't just use the string I'm going to have to use an array for what I want to do :(so a bit more work... but at least it only needs to be a simple array... Link to comment Share on other sites More sharing options...
DrakeTheDragon Posted March 3, 2015 Share Posted March 3, 2015 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 More sharing options...
TheWanderer001 Posted March 4, 2015 Author Share Posted March 4, 2015 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]item1item2..itemX [include]item1item2item3..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 More sharing options...
TheWanderer001 Posted March 4, 2015 Author Share Posted March 4, 2015 (edited) I have tried with various combinations of below...But it seems it is not even recognising the file name ??? string_var sFileorLong sFile (which is how one example shows it) then set sFile to CreateString -1 "test.ini"orlet sFile := CreateString -1 "test.ini" I guess I should try just..set sFile to "test.ini"orlet sFile := "test.ini" {Edit}hmm... neither of them seem to work either ???sFile appears to remains empty :( Edited March 4, 2015 by The-Wanderer Link to comment Share on other sites More sharing options...
QQuix Posted March 4, 2015 Share Posted March 4, 2015 "set sFile to CreateString -1 "test.ini"" should work Check ifsFile 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 More sharing options...
Recommended Posts