It is currently April 23rd, 2024, 7:30 am

Check string variables with one Measure.

Get help with creating, editing & fixing problems with skins
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Check string variables with one Measure.

Post by kyriakos876 »

Hello, I have 4 strings:
Var1=4, Var2=3, Var3=2, Var4=1
I want to have a Measure like

Code: Select all

[Controller]
Measure=String
String=#Var1#:#Var2#:Var3#:#Var4#
IfMatch=??
IfMatchAction=[!Bang]
DynamicVariables=1
That will execute the [!Bang] only if ALL 4 variables are different from their default values: 4,3,2 and 1
For example, if the variables become Var1=100, Var2=10, Var3=8, Var4=90 the bang will be executed. Any ideas? I can do it with 5 measures but I'm pretty sure it's simple and doable with 1 Measure, I just can't really figure it... Maybe something with substitutes ?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Check string variables with one Measure.

Post by jsmorley »

I don't think there is a good way to do this that comes to mind in native Rainmeter. Regular expression is not really suited to doing logical AND tests in this way, and maybe I'm missing something, but I don't see a Substitute that really helps. Knowing that all four variables are the same, or that one or more of them are different, is not hard, but knowing that all four of them are different is tricky.

I'd do it with Lua...

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
Var1=4
Var2=3
Var3=2
Var4=1

[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1

[Controller]
Measure=Calc
IfCondition=([&Lua:CheckVars('4','3','2','1')]) = -1
IfTrueAction=[!Log "None match"]
IfFalseAction=[!Log "One or more match"]
DynamicVariables=1

[MeterOne]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Test.lua:

Code: Select all

function CheckVars(Arg1, Arg2, Arg3, Arg4)

	Var1 = SKIN:GetVariable('Var1')
	Var2 = SKIN:GetVariable('Var2')
	Var3 = SKIN:GetVariable('Var3')
	Var4 = SKIN:GetVariable('Var4')

	if (Var1 ~= Arg1) and (Var2 ~= Arg2) and (Var3 ~= Arg3) and (Var4 ~= Arg4) then
		return -1
	else
		return 1
	end
	
end
Note that since all variables in Rainmeter are strings, I'm passing the arguments to the function as strings, so I don't have to tonumber() anything to do my comparisons. Also note that in Lua "not equal to" is done with ~=, not <> or != as you might expect from using other languages.
User avatar
balala
Rainmeter Sage
Posts: 16162
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Check string variables with one Measure.

Post by balala »

jsmorley's lua approach is probably very good, however I think a native Rainmeter approach also exists. I could write a such code, but before I do this, I have a question: Var1 - Var4 are strings or numbers? Because kyriakos876 you said they are strings, but only numeric values are used in your example. So what they are? Because the Rainmeter solution would be quite different.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Check string variables with one Measure.

Post by kyriakos876 »

jsmorley wrote:I don't think there is a good way to do this that comes to mind in native Rainmeter. Regular expression is not really suited to doing logical AND tests in this way, and maybe I'm missing something, but I don't see a Substitute that really helps. Knowing that all four variables are the same, or that one or more of them are different, is not hard, but knowing that all four of them are different is tricky.

I'd do it with Lua...

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
Var1=4
Var2=3
Var3=2
Var4=1

[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1

[Controller]
Measure=Calc
IfCondition=([&Lua:CheckVars('4','3','2','1')]) = -1
IfTrueAction=[!Log "None match"]
IfFalseAction=[!Log "One or more match"]
DynamicVariables=1

[MeterOne]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Test.lua:

Code: Select all

function CheckVars(Arg1, Arg2, Arg3, Arg4)

	Var1 = SKIN:GetVariable('Var1')
	Var2 = SKIN:GetVariable('Var2')
	Var3 = SKIN:GetVariable('Var3')
	Var4 = SKIN:GetVariable('Var4')

	if (Var1 ~= Arg1) and (Var2 ~= Arg2) and (Var3 ~= Arg3) and (Var4 ~= Arg4) then
		return -1
	else
		return 1
	end
	
end
Note that since all variables in Rainmeter are strings, I'm passing the arguments to the function as strings, so I don't have to tonumber() anything to do my comparisons. Also note that in Lua "not equal to" is done with ~=, not <> or != as you might expect from using other languages.
This is nice and cured the headache I created to myself trying to figure it out with reg-exp and substitutes, but as you said, substitutes are useless and reg-exp, I ain't no expert on that but I didn't figure anything that doesn't include writing all the possible combinations and if it's not one of them, execute the bang. But that's stupid and if I were to add one more variable to the game, CHAOS! because now the combinations are 4*3*2*1, you add one more, it becomes 5*4*3*2*1 and so on.
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Check string variables with one Measure.

Post by kyriakos876 »

balala wrote:jsmorley's lua approach is probably very good, however I think a native Rainmeter approach also exists. I could write a such code, but before I do this, I have a question: Var1 - Var4 are strings or numbers? Because kyriakos876 you said they are strings, but only numeric values are used in your example. So what they are? Because the Rainmeter solution would be quite different.
those variables are RGB values to be exact, so strings with numbers and commas. I can too do it with 3 ways until now, but all 3 of them are stupid.
User avatar
balala
Rainmeter Sage
Posts: 16162
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Check string variables with one Measure.

Post by balala »

kyriakos876 wrote:those variables are RGB values to be exact, so strings with numbers and commas. I can too do it with 3 ways until now, but all 3 of them are stupid.
But Var1, Var2 and so on are numbers. Have you dissected some way the color code?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Check string variables with one Measure.

Post by jsmorley »

Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
MyColor=112,255,212,255

[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1

[Controller]
Measure=Calc
IfCondition=([&Lua:CheckColor('112,255,212,255')]) = -1
IfTrueAction=[!Log "None of the color elements match"]
IfFalseAction=[!Log "One or more color elements match"]
DynamicVariables=1

[MeterOne]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Test.lua:

Code: Select all

function CheckColor(Arg1)

	startColor = Arg1
	startRed = string.match(startColor, '(%d+).*')
	startGreen	= string.match(startColor, '%d+,(%d+).*')
	startBlue = string.match(startColor, '%d+,%d+,(%d+).*')
	startAlpha = string.match(startColor, '%d+,%d+,%d+,(%d+)')
	
	varColor = SKIN:GetVariable('MyColor')
	varRed = string.match(varColor, '(%d+).*')
	varGreen	= string.match(varColor, '%d+,(%d+).*')
	varBlue = string.match(varColor, '%d+,%d+,(%d+).*')
	varAlpha = string.match(varColor, '%d+,%d+,%d+,(%d+)')
	
	if (varRed ~= startRed) and (varGreen ~= startGreen) and (varBlue ~= startBlue) and (varAlpha ~= startAlpha) then
		return -1
	else
		return 1
	end
	
end
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Check string variables with one Measure.

Post by kyriakos876 »

balala wrote:But Var1, Var2 and so on are numbers. Have you dissected some way the color code?
I could get the R,G and B dissected with the plugin, but I thought as they are strings, for example Var1=255,0,0 etc... it should be fine...
User avatar
kyriakos876
Posts: 919
Joined: January 30th, 2017, 2:01 am
Location: Greece

Re: Check string variables with one Measure.

Post by kyriakos876 »

jsmorley wrote:Skin:

Code: Select all

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

[Variables]
MyColor=112,255,212,255

[Lua]
Measure=Script
ScriptFile=Test.lua
Disabled=1

[Controller]
Measure=Calc
IfCondition=([&Lua:CheckColor('112,255,212,255')]) = -1
IfTrueAction=[!Log "None of the color elements match"]
IfFalseAction=[!Log "One or more color elements match"]
DynamicVariables=1

[MeterOne]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Test.lua:

Code: Select all

function CheckColor(Arg1)

	startColor = Arg1
	startRed = string.match(startColor, '(%d+).*')
	startGreen	= string.match(startColor, '%d+,(%d+).*')
	startBlue = string.match(startColor, '%d+,%d+,(%d+).*')
	startAlpha = string.match(startColor, '%d+,%d+,%d+,(%d+)')
	
	varColor = SKIN:GetVariable('MyColor')
	varRed = string.match(varColor, '(%d+).*')
	varGreen	= string.match(varColor, '%d+,(%d+).*')
	varBlue = string.match(varColor, '%d+,%d+,(%d+).*')
	varAlpha = string.match(varColor, '%d+,%d+,%d+,(%d+)')
	
	if (varRed ~= startRed) and (varGreen ~= startGreen) and (varBlue ~= startBlue) and (varAlpha ~= startAlpha) then
		return -1
	else
		return 1
	end
	
end
I am using your plugin actually:
https://forum.rainmeter.net/viewtopic.php?f=5&t=28115&p=146123&hilit=colorpicker#p146123

so if I wanted I could get the RGBs but is there a point? You noted above that this works for strings and they don't have to be numbers, am I wrong? I am converting the variables and the arguments now to check if your lua works with variables like :Var1=255,0,0 (The alpha will always be 255 in my case just saying)

EDIT: Just implemented it in my skin and it works fine without needing to dissect the values.
Last edited by kyriakos876 on September 20th, 2018, 2:34 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Check string variables with one Measure.

Post by jsmorley »

kyriakos876 wrote:I am using your plugin actually:
https://forum.rainmeter.net/viewtopic.php?f=5&t=28115&p=146123&hilit=colorpicker#p146123

so if I wanted I could get the RGBs but is there a point? You noted above that this works for strings and they don't have to be numbers, am I wrong? I am converting the variables and the arguments now to check if your lua works with variables like :Var1=255,0,0 (The alpha will always be 255 in my case just saying)
You will have to change the Lua a bit to eliminate checking the alpha value, but sure...