ArrayToINIsection
Jump to navigation
Jump to search
A User Function for use with Oblivion Script Extender
Syntax:
ArrayToINIsection SerialArray:array, Filename:string, SectionName:string
Writes an array to a Pluggy INI file
The arguments are:
- SerialArray - the array to write - must be one dimensional - see ArraySerialize
- Filename - a string with the name of the file
- SectionName - a string with the name of the INI section
Notes[edit | edit source]
- The input array must be a StringMap type, serialized array. Second level arrays, if present, will be ignored.
Usage[edit | edit source]
Call ArrayToINIsection MySerialArray "MyFilename.ini" "Section51"
If MySerialArray looks like this:
['EntryA_Attr1'] = 'A' ['EntryA_Attr1_0_Value1'] = 11 ['EntryA_Attr1_0_Value2'] = 22 ['EntryA_Attr1_1_Value1'] = 1111 ['EntryA_Attr1_1_Value2'] = 2222 ['EntryB_Attr1'] = 'B' . . . etc
The INI section will be this:
[Section51] EntryA_Attr1='A' EntryA_Attr1_0_Value1=11 EntryA_Attr1_0_Value2=22 EntryA_Attr1_1_Value1=1111 EntryA_Attr1_1_Value2=2222 EntryB_Attr1='B' . . . etc
Code[edit | edit source]
scn zzzArrayToINIsection
;---------------------------------------
; Writes an INI section with data received in the input array
;---------------------------------------
array_var asEntry
array_var asSerial
float v
ref reff
short i
string_var sFilename
string_var sKey
string_var sSection
string_var sText
long psFile ;===Pluggy===
long psSection ;===Pluggy===
long psKey ;===Pluggy===
long psValue ;===Pluggy===
begin Function {asSerial sFilename sSection }
;=== Initialize ===
let psFile := createstring -1 0 1 1
let psSection := createstring -1 0 1 1
let psKey := createstring -1 0 1 1
let psValue := createstring -1 0 1 1
setstring psSection $sSection
setstring psFile $sFilename
;=== DELETE existing section ===
IniDelKey psFile psSection
foreach asEntry <- asSerial
;=== Set the key ===
let sKey := asEntry[key]
setString psKey $sKey
;=== Set the value ===
if eval (typeof asEntry[value]) == "String"
let sText := "'" + asEntry[value] + "'"
setString psValue $sText
IniWriteString psFile psSection psKey psValue
elseif eval (typeof asEntry[value]) == "Number"
let v := asEntry[value]
let sText := $v
setString psValue $sText
IniWriteString psFile psSection psKey psValue
elseif eval (typeof asEntry[value]) == "Form"
let reff := asEntry[value]
let sText := "0x" + GetFormIDString reff
setString psValue $sText
IniWriteString psFile psSection psKey psValue
endif
loop
DestroyString psFile
DestroyString psSection
DestroyString psKey
DestroyString psValue
sv_destruct sKey sText
end
See Also[edit | edit source]