Difference between revisions of "Introduction to Pluggy INI Files"

Add examples
imported>Speedo
imported>Speedo
(Add examples)
Line 98: Line 98:
*[[IniKeyExists]]
*[[IniKeyExists]]
*[[IniDelKey]]
*[[IniDelKey]]
==Examples==
====Loading Data From INI====
Going back to the previous [[Pluggy INI Files#Keys|example INI]], the following script can be used to load data from the INI into Oblivion:
<pre>
;Variables where the data will be stored
long name
long level
long gold
float health
ref spell
ref weapon
;Variables needed to feed the IniRead___ functions
long file
long section
long key
;Variables for default values
long dInt
float dFloat
ref dRef
...
set file to CreateString -1 "myConfigFile.ini"
set section to CreateString -1 "General"
set key to CreateString -1 "Name"
set name to CreateString
set dInt to CreateString -1 "Unknown Name"
IniReadString name file section key dInt
DestroyString dInt
SetString key "Level"
set dInt to -1
set level to IniReadInt file section key dInt
SetString key "Gold"
set gold to IniReadInt file section key dInt
SetString section "Attributes"
SetString key "Health"
set dFloat to -1
set health to IniReadFloat file section key dFloat
SetString section "Spells"
SetString key "ActiveSpell"
set dRef to 0
set spell to IniReadRef file section key dRef
SetString section "Equipped Items"
SetString key "Weapon"
set weapon to IniReadRef file section key dRef
DestroyString file
DestroyString section
DestroyString key
</pre>
====Saving Data to INI====
Again using the [[Pluggy INI Files#Keys|example INI]], this script could be used to update the values in the INI with the player's current information:
<pre>
;Variables to feed the IniWrite___ functions
long file
long section
long key
;Temp variables to hold data before it is saved
long tempL
float tempF
ref tempR
...
set file to CreateString -1 "myConfigFile.ini"
set section to CreateString -1 "General"
set key to CreateString -1 "Name"
set tempL to CreateString
StringGetName player tempL
IniWriteString file section key tempL
DestroyString tempL
SetString key "Level"
set tempL to player.GetLevel
IniWriteInt file section key tempL
SetString key "Gold"
set tempL to player.GetGold
IniWriteInt file section key tempL
SetString section "Attributes"
SetString key "Health"
set tempF to player.GetAV health
IniWriteFloat file section key tempF
SetString section "Spells"
SetString key "ActiveSpell"
set tempR to GetPlayerSpell
IniWriteRef file section key tempR
SetString section "Equipped Items"
SetString key "Weapon"
set tempR to player.GetEquippedObject 9
IniWriteRef file section key tempR
DestroyString file
DestroyString section
DestroyString key
</pre>


[[Category: Pluggy]]
[[Category: Pluggy]]
Anonymous user