GetStringFromFile get custom string from external file or string
finds first string between Startkey and EndKey after StringKey.
similar to localization but no need to worry about nesting strings in a translation file this way.
Example: Let's say you have a file Data/interface/MyStrings.txt that contains:
MyStringA = [My String A]
MyStringB = [My String B]
String MyStringB = GetStringFromFile("MyStringB", FilePath = "Data/interface/MyStrings.txt") ;Returns "My String B"
To search a string instead of a file path, you can do this:
String MyStrings
MyStrings = MiscUtil.ReadFromFile("Data/interface/MyStrings.txt")
String MyStringB = GetStringFromFile("MyStringB", MyStrings) ;Returns "My String B"
Note, if using the function this way, don't store MyStrings in the script, outside of events or functions. Storing large strings can cause CTD on game load.
If storing this way, be sure to clear the string by doing: MyStrings = "" after it's finished being used.
This method will be better for performance if you need to get a lot of strings from your file, as it won't use MiscUtil.ReadFromFile everytime you use the function.
StringKeys contained in the file must be unique.
If the stringkey wasn't found and the Default is "", it returns the stringKey
Let's say you have:
Some Custom Message = [Some Custome Message]
in the "Data/interface/MyStrings.txt file"
You can do:
debug.notification(GetStringFromFile("Some Custom Message", FilePath = "Data/interface/MyStrings.txt"))
And it will still show "Some Custom Message" if something went wrong and it wasn't found in the file
You can specify a default if you want something else to return if the stringKey wasn't found.
Requires PapyrusUtil && SKSE