LavishSettings Tutorial

mycroft

Script Author: MyPrices
I promised someone a basic walkthrough into Lavishsettings...

But I thought others might find it useful so I'm posting it here.

An introduction to Lavishsettings by Mycroft


LavishSettings don't use a variable to access a particular bit of information in a settings file.

What they use is Pointers , these pointers locate where the information you want to access is held in RAM.

LavishSettings files have 'levels'

Level 1 is the Master Pointer to the 'top' of the Data it's similar to naming an array.

Level 2 are Sections within the 'dataset'.

Level 3 could be sub-sections within the Sections..

For example, using the Myprices script.

I name the data as a whole as myprices.

The data has several Sections (sets).

General where the script settings are saved.
Item Where the sale item details are saved
Buy Where the Items you want to buy are saved.


I have to define reference pointers to keep track of where the sections (sets) are held in memory.

So at the top of the script outside the main function I use

Code:
variable settingsetref General
variable settingsetref Item
variable settingsetref Buy


I then have to create the LavishSettings template for the information to be stored in.

Code:
; Main LavishSettings Pointer
LavishSettings:AddSet[myprices]

; Pointers to Datasets inside the myprices Setting 'array'
LavishSettings[myprices]:AddSet[General]
LavishSettings[myprices]:AddSet[Item]
LavishSettings[myprices]:AddSet[Buy]

I then have to put the memory location of each of these into the reference pointers we defined earlier.

To do this we use the FindSet command.

Code:
Item:Set[${LavishSettings[myprices].FindSet[Item]}]

Buy:Set[${LavishSettings[myprices].FindSet[Buy]}]

General:Set[${LavishSettings[myprices].FindSet[General]}]
This puts the location of the created Sets into the reference variables.


Adding/Updating Data into each Set.

To add a setting outside the General,Item or buy Sets you would use the AddSetting command

Code:
LavishSettings[myprices]:AddSetting[AutoRun,${autorun}]
What you are saying here is Add to the myprices (global) set a Setting Named AutoRun and set it to the value held in variable ${autorun}

To add a 'Setting' into The General Set for example...

So to add a bool variable "MatchLowPrice" as a setting into the General Set you would use.

Assuming you had a bool variable named matchlow which held the information.

Code:
General:AddSetting[MatchLowPrice,${matchlow}]
What you are saying here is Add to the General set a Setting Named MatchLowPrice and set it to the value held in variable ${matchlow}


To read that Setting from the information in the General Set you use FindSetting

Code:
matchlow:Set[${General.FindSetting[MatchLowPrice]}]
What you are saying above is , Look in the General Set for a setting named MatchLowPrice and put it in the variable matchlow.



Saving your data.

To save your Sets and settings you use the command Export

So to save the myprices set (Everything including all the General , Item and Buy Sets).

Code:
	LavishSettings[myprices]:Export[${filepath}filename.XML]
This will save everything in the myprices set as a whole.


To Load your sets into memory you use the command Import

Code:
	LavishSettings[myprices]:Import[${filepath}filename.XML]
This takes your data file and slots all the information into the correct Sets ready to be read and manipulated.


Clearing the data from your RAM

When you exit the script , the data is still held in RAM , it needs to be cleared , usually this is done using the atexit atom

Code:
atom atexit()
{
	if !${ISXEQ2.IsReady}
		return

	LavishSettings[myprices]:Clear
}

Hope this helps...it's not everything but should get someone started.
 
Last edited:

Valerian

ISX Specialist
I've also written a helper object include file, currently in the SVN as EQ2Common/SettingManager.iss -- It may be more advanced than some people want to use. For example usage, see eq2inventory.iss
 

mycroft

Script Author: MyPrices
More complicated

Sometimes you want to step through the Sets and settings one by one without looking for specific information.

This is definately more complicated.


You still need reference pointers as you did before , but you also need a different type called iterators.

The best way to describe these would be a counter that you can increase to move through the Sets, Sub-Sets and settings 1 by one.

The first thing you need to do is put the memory location of the set and the memory location of the sub-sets you want to scan through into a reference pointer.

So we define both outside the main() function at the top.

Code:
variable settingsetref BuyList
variable settingsetref BuyName
define the iterators (counters) for the sets and settings...

There are 3 levels to the datafile I use

Code:
Main Set (Item)
	Sub-Set Name (Item Name)
			Data (All the various information about that item)
So I need 3 iterators

Code:
variable iterator BuyIterator
variable iterator NameIterator
variable iterator BuyNameIterator
get the location of the set and put it in the reference pointer.

Code:
BuyList:Set[${LavishSettings[myprices].FindSet[Item]}]
I then get the pointer to the First Entry in the Set (The Name of the Set) using GetSetIterator

Code:
BuyList:GetSetIterator[BuyIterator]


I check to see if there is any information there (Any set at all)

Code:
if ${BuyIterator:First(exists)}
{
If there isn't then no point continuing

Then we read the pointer to the First Sub-Set

Code:
;start going through each Sub-Set under [Item]
	do
	{
		; Get the Sub-Set Location
		NameIterator.Value:GetSetIterator[BuyIterator]
		do
		{
This gives us the location of the first Sub-Set


We then get the memory pointer to that first Sub-Set.

Code:
		; Get the reference for the Sub-Set
		BuyName:Set[${BuyList.FindSet[${BuyIterator.Key}]}]
and get the location of the first entry in that Sub-Set

Code:
		; Create an Index of all the data in that Sub-set
		BuyName:GetSettingIterator[BuyNameIterator]
Now we have the location of the first Sub-Set in memory (The Name of the first item)


Check to see if there are actually any Sub-Sets

Code:
		; read the Settings in the Sub-Set
		if ${BuyNameIterator:First(exists)}
		{

if there are then step through the Sub-Sets reading all the information.

You can react to the information by using the Switch command

Code:
		do
		{
			Switch "${BuyNameIterator.Key}"
			{
The .Key contains the actual NAME of the Setting you are currently looking at.

Use the Case command react and read the information/run a function , set a variable , return a value , it's upto you...

Code:
				Case BuyNumber
					Number:Set[${BuyNameIterator.Value}]
					break
Here if the NAME of the setting read is 'BuyNumber' I'm taking the VALUE of that setting and storing it in a variable.

We then check to see if there are any more Settings to read in that sub-set.

Code:
			}
		}
		while ${BuyNameIterator:Next(exists)}
We then check for any more Sub-Sets

Code:
	}
	; Keep looping till you've read all the Sub-Sets
	while ${NameIterator:Next(exists)}
and Finally we keep moving through all the Sets , in myprices thats General , Item or Buy until you reach the end of all your Sets.

Code:
}
While ${BuyIterator:Next(exists)}

It takes a while to understand this (not sure I understand it 100% myself yet) , but stick with it and you can do a lot with the above.
 
Last edited:
Top Bottom