Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
MyGoodVar=20,20,20|10,10,10|20,20,20
MyBadVar1=20,20,20|20,20,20|20,20,20
MyBadVar2=10,10,10|10,10,10|20,20,20
[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1
[MeterResult]
Meter=String
FontSize=12
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=MyGoodVar is: [Lua:ColorTest('#MyGoodVar#')]#CRLF#MyBadVar1 is: [Lua:ColorTest('#MyBadVar1#')]#CRLF#MyBadVar2 is: [Lua:ColorTest('#MyBadVar2#')]
DynamicVariables=1
Code: Select all
function ColorTest(inArg)
splitBits = {}
for oneBit in string.gmatch(inArg, '[^|]+') do
table.insert(splitBits, oneBit)
end
if splitBits[1] == '20,20,20' and splitBits[2] ~= '20,20,20' and splitBits[3] == '20,20,20' then
return 1
else
return -1
end
end
This creates an "iterator" that marches through the string, capturing any bits that are not "|" (our separator) and sticking them into a table. This "splits" the string on the separator, into the table. Then we can test the fields in the table for "==" (equal) and "~=" (not equal) to determine our result.
You can use this result any way you want, for instance in an IfCondition on a measure to then use bangs to change something. My example simply displays the result.
Whether you use this for this particular need or not, feel free to throw a blizzard of measures at it instead, knowing how to "split" a string on a separator in Lua is a very useful thing to have in your toolbelt.