It is currently March 29th, 2024, 3:36 pm

reset variables

Discuss the use of Lua in Script measures.
User avatar
pds
Posts: 79
Joined: April 12th, 2014, 12:52 pm
Location: Slovakia

reset variables

Post by pds »

I have variables :

radio0=0
radio1=0
radio2=0
radio3=0
radio4=0
radio5=0
radio6=0
radio7=0
radio8=0

and i have to change some of them to 1 and others must be 0. Now i have this :

Code: Select all

LeftMouseUpAction=[!SetVariable radio1 (1-#radio1#)][!SetVariable radio0 0][!SetVariable radio2 0][!SetVariable radio3 0][!SetVariable radio4 0][!SetVariable radio5 0][!SetVariable radio6 0][!SetVariable radio7 0][!SetVariable radio8 0][!UpdateMeter *][!Redraw]
it works but its to long and complicated :). I thing lua script is better way, but i have never make this before.
I want some like this: reset(2) it means radio2=1 and others =0

Can you help me ?
Last edited by pds on February 23rd, 2016, 5:40 pm, edited 1 time in total.
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: reset variables

Post by jsmorley »

Well, I'm not sure I would say this is "less long and complicated", but:

Skin:

Code: Select all

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

[Variables]
NumOfVars=9
radio0=0
radio1=0
radio2=0
radio3=0
radio4=0
radio5=0
radio6=0
radio7=0
radio8=0

[MeasureToggle]
Measure=Script
ScriptFile=Test.lua
UpdateDivider=-1

[MeterZero]
Meter=String
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=radio0 = #radio0#
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure MeasureToggle "ToggleVar(0)"]

[MeterOne]
Meter=String
Y=0R
FontSize=11
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=radio1 = #radio1#
DynamicVariables=1
LeftMouseUpAction=[!CommandMeasure MeasureToggle "ToggleVar(1)"]
Test.lua:

Code: Select all

function Initialize()

	numOfVars = SKIN:GetVariable('NumOfVars')

end
	
function Update()

	return numOfVars

end

function ToggleVar(varNum)

	currentValue = SKIN:GetVariable('radio'..varNum)
		
	for i = 0, numOfVars -1 do
		SKIN:Bang('!SetVariable', 'radio'..i, '0')
	end

	SKIN:Bang('!SetVariable', 'radio'..varNum, 1 - currentValue)
	SKIN:Bang('!UpdateMeter', '*')
	SKIN:Bang('!Redraw')
	
end
test.gif
P.S. None of my business, but I'd be tempted to make the variables "1-based" instead of "0-based", so you have radio1...radio9, NumOfVars is still "9", and you change the loop in the .lua to:

Code: Select all

	for i = 1, numOfVars do
		SKIN:Bang('!SetVariable', 'radio'..i, '0')
	end
Just one less thing to think about, there are 9 variables numbered 1..9 and somehow in this instance that seems more logical than 0...8.
You do not have the required permissions to view the files attached to this post.
User avatar
pds
Posts: 79
Joined: April 12th, 2014, 12:52 pm
Location: Slovakia

Re: reset variables

Post by pds »

Thak you so much as usually :)

And i think now it is MUCH easier than before :
before :

Code: Select all

[MeterButton0]
meter=image
ImageName=#@#Images\button_#radio0#.png
X=2r
Y=#prvybutty#
PreserveAspectRatio=1 
LeftMouseUpAction=["#Player#" #r0#][!SetVariable radio0 (1-#radio0#)][!SetVariable radio1 0][!SetVariable radio2 0][!SetVariable radio3 0][!SetVariable radio4 0][!SetVariable radio5 0][!SetVariable radio6 0][!SetVariable radio7 0][!SetVariable radio8 0][!UpdateMeter *][!Redraw][#PlayClick#]
DynamicVariables=1
ToolTipText=#rn0#

[MeterButton1]
meter=image
ImageName=#@#Images\button_#radio1#.png
X=2r
Y=#prvybutty#
PreserveAspectRatio=1
LeftMouseUpAction=["#Player#" #r1#][!SetVariable radio1 (1-#radio1#)][!SetVariable radio0 0][!SetVariable radio2 0][!SetVariable radio3 0][!SetVariable radio4 0][!SetVariable radio5 0][!SetVariable radio6 0][!SetVariable radio7 0][!SetVariable radio8 0][!UpdateMeter *][!Redraw][#PlayClick#]
DynamicVariables=1
ToolTipText=#rn1#
after :

Code: Select all

[MeterButton0]
meter=image
ImageName=#@#Images\button_#radio0#.png
X=2r
Y=#prvybutty#
PreserveAspectRatio=1 
LeftMouseUpAction=["#Player#" #r0#][!CommandMeasure MeasureToggle "ToggleVar(0)"][#PlayClick#]
DynamicVariables=1
ToolTipText=#rn0#

[MeterButton1]
meter=image
ImageName=#@#Images\button_#radio1#.png
X=2r
Y=#prvybutty#
PreserveAspectRatio=1
LeftMouseUpAction=["#Player#" #r1#][!CommandMeasure MeasureToggle "ToggleVar(1)"][#PlayClick#]
DynamicVariables=1
ToolTipText=#rn1#