The Classic Solution
You can merely have a key for every value you want to store.
SomeVariables.inc
Code: Select all
[Variables]
Key1=
Key2=
Key3=
...
Code: Select all
[Variables]
@Include=#CURRENTPATH#SomeVariables.inc
[MeterNote1]
Meter=String
Text=#Key1#
Code: Select all
!WriteKeyValue Variables Key1 "#UserInput#" "#CURRENTPATH#SomeVariables.inc"
Code: Select all
[!SetVariable Key1 "#UserInput#"][!WriteKeyValue Variables Key1 "#UserInput#" "#CURRENTPATH#SomeVariables.inc"]
You can use delimiters in values to store multiple in CSV (comma separated value) format.
A live example: In my GW2 World Boss Timer, there are 96 15-minute time slots in a day, and I want to mark any one or multiple of them for audio alerts. Instead of storing 96 keys, I use 1 key:
Code: Select all
AlertSlot=,65,5,24,
Retrieval works as follows:
Code: Select all
function Initialize()
alertSlot = SKIN:GetVariable('AlertSlot')
end
function Alert()
if alertSlot:find(','..currSlot..',') then
SKIN:Bang('Play "#SoundFile#"')
end
end
Code: Select all
function SetAlert(n)
alertSlot = alertSlot:find(','..currSlot..',') and alertSlot:gsub(','..currSlot..',', ',') or alertSlot..currSlot..','
SKIN:Bang('!WriteKeyValue Variables AlertSlot "'..alertSlot..'" "#CURRENTPATH#Settings.inc"')
end
Also, in this application, alertSlot was only used in Lua, so I did not bother using !SetVariable. Rainmeter will only show AlertSlot as it was when it was first loaded, while I keep the equivalent Lua variable up-to-date.
Sparse Matrix
For, say, a calendar with notes, you will need those values to be indexed, requiring a 2D, 3D, or xD array. This is easily done with 2 delimiters.
Code: Select all
Notes=¦2014·6·3·"Buy milk, cookies."¦2014·6·25·"Chemotherapy 2pm"¦
Also note that the empty key must look like this:
Code: Select all
Notes=¦
Code: Select all
function Initialize()
notes = SKIN:GetVariable('Notes')
end
function DisplayCalendar(year, month)
for day = 1, NumDays(month) do
if notes.find('¦'..year..'·'..month..'·'..day..'·.*¦') then
SKIN:Bang('!SetOption MeterDay'..day..'Note Text '..notes.match('¦'..year..'·'..month..'·'..day..'·(.*)¦'))
end
end
SKIN:Bang('!Update')
end
Code: Select all
function SetNote(year, month, day, note)
EraseNote(year, month, day)
if note ~= "" then
notes = notes..year..'·'..month..'·'..day..'·"'..note..'"¦'
SKIN:Bang('!WriteKeyValue', 'Variables', 'Notes', notes)
end
end
Code: Select all
function EraseNote(year, month, day)
notes = notes:gsub('¦'..year..'·'..month..'·'..day..'·.*¦', '¦')
SKIN:Bang('!WriteKeyValue', 'Variables', 'Notes', notes)
end