YouDoNotKnowMyName Posted October 10, 2020 Share Posted October 10, 2020 Good evening everybody! So, I am new to this whole "scripting" thing ...But I think I understand the "basics" like events, functions, properties, ... I was thinking about implementing some stuff with a script and the following questions about arrays came up: How many "entries" can an array have in FO4? Can I "save" an array or can it just be used in the script that "defines" it? Can you import / export the contents of an array from / into a CSV or TXT file? The CK wiki article about "arrays" isn't really helpful, it just talks about using arrays inside of scripts. Could some of the scripting gods here (or anybody else who knows this) please share their knowledge about this?Thanks ... Link to comment Share on other sites More sharing options...
dylbill Posted October 10, 2020 Share Posted October 10, 2020 (edited) You can save an array inside of a script, and access it from other scripts if you wish. Arrays in papyrus can have a max of 128 entries. Here's an example: Scriptname TestModQuestScript extends Quest Int[] Property IntArray Auto Event OnInit() IntArray = New Int[128] ;initialize array IntArray[0] = 0 IntArray[1] = 1 ;Ect EndEvent In another script, to access the above script and its array. TestModQuestScript Property ScriptRef Auto ;In the CK, choose the form the script is attached to. In the example, it's a quest Event SomeEvent() Int ZeroPosInt = ScriptRef.IntArray[0] ;to change and save the int in the array ScriptRef.IntArray[1] = 100 EndEvent Edited October 10, 2020 by dylbill Link to comment Share on other sites More sharing options...
YouDoNotKnowMyName Posted October 10, 2020 Author Share Posted October 10, 2020 (edited) Thanks for the quick answer! So an array can only have 128 "entries"?Ugghhh .. that is very very few ... (Kind of reminds me of programming embedded microcontrollers that only have a few kB of memory ...) So arrays are like global variables that can be "accessed" from "anywhere at anytime"?Also, if they are a "property", is there some sort of an "object" in the CK that is associated with them?(Like if you have an "actor" as a property, you can "fill" that property with an actor reference ...) Also: Aren't "formlists" kind of like arrays of references? Edited October 10, 2020 by YouDoNotKnowMyName Link to comment Share on other sites More sharing options...
dylbill Posted October 10, 2020 Share Posted October 10, 2020 (edited) No problem. If you set up an array as a property, it is like a global variable and can be accessed from other scripts, as long as the form that the script is attached to exists, or is running in game. If you did this: Int[] IntArray Event OnInit() IntArray = New Int[128] ;initialize array IntArray[0] = 0 IntArray[1] = 1 ;Ect EndEvent The array couldn't be accessed from other scripts, but can be accessed from other events or functions in the same script. If you set the array as a property, then you can fill the array in the CK manuely, or fill the array with your script. To get more entries, you can do an array of array's. Unfortunately there is no native support for this in papyrus, but you can fake it. Here's how: Create a new MiscItem, I just duplicated the Bobby Pin and called it StorageMiscItem. Put a script on the StorageMiscItem that has an array property like so: Scriptname MiscStorageItemScript extends ObjectReference String[] Property StringArray Auto Compile the script. That's all the script needs. Then make a new empty cell, and drag one of the StorageMiscItem's into it. Edit the reference, uncheck the respawns box and change its ID name to StorageObjectRef, or any name you want so you can access it from another script. In another script, you can create new object references that have arrays stored because of the inherited script. Example of creating a 3X3 multi dimensional array: Scriptname QuestStorageScript extends Quest ObjectReference[] Property StorageObjects Auto ObjectReference Property StorageObjectRef Auto ;this is the object reference in the empty cell MiscObject Property StorageMiscItem Auto ;The misc item with the script attached Event OnInit() Utility.Wait(1) StorageObjects = New ObjectReference[3] Int I = -1 While I < 2 I += 1 StorageObjects[I] = StorageObjectRef.PlaceAtMe(StorageMiscItem, 1, 1, 0, 0) ;create a new persistent storage item which contains a string array MiscStorageItemScript ScriptRef = StorageObjects[I] as MiscStorageItemScript ;access the storage item's script ScriptRef.StringArray = New String[3] ;initialize string array on storage item with 3 entries Int IA = -1 While IA < 2 IA += 1 ScriptRef.StringArray[IA] = ("Test " + I + " - " + IA) ;store string in storage item's string array EndWhile EndWhile Int IB = -1 String TestPrintout While IB < 2 IB += 1 MiscStorageItemScript ScriptRef = StorageObjects[IB] as MiscStorageItemScript ;access the storage item's script Int IC = -1 While IC < 2 IC += 1 TestPrintout += "\n" + ScriptRef.StringArray[IC] ;add new line plus storage string entry to printout string EndWhile EndWhile Utility.Wait(1) Debug.MessageBox(TestPrintout) EndEvent In short, you store an array on an a persistent object reference with its inherited script, and you store those object references in an array in another script. The advantage of doing this is that there's minimal setup, and can basically create arrays at runtime. To make a formlist of formlists, you need to create them first in the creation kit. The downside of doing this, is you're creating persistent object references, which if you make too many, can cause save bloat issues. So use this technique sparingly. Formlists are like arrays, but they can hold any type of form, where as arrays can only hold 1 type. Formlists also can't hold certain data, like float's, int's, string's ect. Edited October 10, 2020 by dylbill Link to comment Share on other sites More sharing options...
YouDoNotKnowMyName Posted October 11, 2020 Author Share Posted October 11, 2020 Ah ok, so arrays are for "data", formlists are for anything else ... Thanks for showing me that trick with the arrays ...I will play around with that ... You really helped me a lot! That still leaves question 3 to be answered ... Link to comment Share on other sites More sharing options...
dylbill Posted October 11, 2020 Share Posted October 11, 2020 I'm not sure if you can export to txt or other formats in FO4. I know there are a few mods that do that for Skyrim. The FO4 MCM reads data from Json files, so with using their API it might be possible. Link to comment Share on other sites More sharing options...
YouDoNotKnowMyName Posted October 11, 2020 Author Share Posted October 11, 2020 I'm not sure if you can export to txt or other formats in FO4. I know there are a few mods that do that for Skyrim. The FO4 MCM reads data from Json files, so with using their API it might be possible.Yes I know that Skyrim can do that.There was a mod for Skyrim tht let you write journal entries, like a diary, in game.You could export that text somehow ... Weird that the Script Extender for Skyrim has more "functionality" then the one for FO4 ... (it seems that way to me ...) Link to comment Share on other sites More sharing options...
Blinxys Posted October 11, 2020 Share Posted October 11, 2020 At some point I accidentally exported all the contents of all books from CK.(I didn't realize it happened until i found the folder in my game install). :huh:So, if you can get your (populated) array to show up in CK object hierarchy tree try right click and see if "export ..." option exists.(I think that's how I did it, it's in there somewhere). :unsure: Link to comment Share on other sites More sharing options...
YouDoNotKnowMyName Posted October 11, 2020 Author Share Posted October 11, 2020 Yes, I know you can export it from the CK (or with xEdit), but I mean exporting it at "runtime".(So when the game actually runs, by hitting a key or selecting something in an MCM menu) Link to comment Share on other sites More sharing options...
Blinxys Posted October 11, 2020 Share Posted October 11, 2020 All i know is MCM is supposed to save an INI when defaults change.So it has output capabilities, as far as arrays go? why not!Related to your mentioning it: Journal of the Soul Survivor. That's a holotape, but PPL (including myself) are looking for export/output from that as well.(hint, hint). :yes:(It's trapped inside saved game data currently). Link to comment Share on other sites More sharing options...
Recommended Posts