It is currently April 26th, 2024, 11:40 pm

Reader

Discuss the use of Lua in Script measures.
Alex Becherer

Re: Reader

Post by Alex Becherer »

thanks for the quick fix. it's working again.
User avatar
Saiho
Posts: 46
Joined: September 24th, 2012, 2:11 pm

Re: Reader

Post by Saiho »

I'm looking for a way to make my reader cycle between 5 feeds and show for each feed it's corresponding button.

Code: Select all

[mReadRotate]
Measure=Calc
Formula=(mReadRotate < 5) ? mReadRotate+1 : 1
IfEqualValue=3
IfEqualAction=[!CommandMeasure mReaderScript Show([mReadRotate])][!HideMeterGroup gRButtonp][!ShowMeter RButton[mReadRotate]p]
This works more or less, hiding all the wrong buttons and showing me the 3rd feed and the button called RButton3p every time the measure's value is 3.

So, I would expect this:

Code: Select all

Measure=Calc
Formula=(mReadRotate < 5) ? mReadRotate+1 : 1
IfAboveValue=0
IfAboveAction=[!CommandMeasure mReaderScript Show([mReadRotate])][!HideMeterGroup gRButtonp][!ShowMeter RButton[mReadRotate]p]
to show me the a different feed and button on every update. What have I got wrong?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Reader

Post by Kaelri »

Rainmeter's IfActions only apply once when the value matches the condition. They don't fire again until after the value changes back to something that does not match. In your case, mReadRotate is always "above" 0, so the action is only triggered once, when the skin first loads.

Since the script already has "ShowNext" and "ShowPrevious" commands built-in, you can use a much simpler counter measure to switch feeds:

Code: Select all

[mReadRotate]
Measure=Calc
Formula=(mReadRotate % 5) + 1
IfEqualValue=0
IfEqualAction=!CommandMeasure mReaderScript ShowNext()
The script also creates a variable called "CurrentFeed" variable for the currently-displaying feed number. You can use this to show and hide your button groups - for example, using the "FinishAction" option, also provided by the script:

Code: Select all

[mReaderScript]
...
FinishAction=[!HideMeterGroup gRButtonp][!ShowMeter RButton#CurrentFeed#p]
User avatar
Saiho
Posts: 46
Joined: September 24th, 2012, 2:11 pm

Re: Reader

Post by Saiho »

Ugh.. I completely missed the CurrentFeed part. It does make things a lot simpler!
I chose the Formula=(mReadRotate < 5) ? mReadRotate+1 : 1 because I don't really understand the role of % in formulas. Does it have some advantage?
User avatar
Saiho
Posts: 46
Joined: September 24th, 2012, 2:11 pm

Re: Reader

Post by Saiho »

Also, some feeds don't give a description variable. Is there a simple way to make the description meter not show at all if it has nothing to display?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Reader

Post by Kaelri »

Saiho wrote:I chose the Formula=(mReadRotate < 5) ? mReadRotate+1 : 1 because I don't really understand the role of % in formulas. Does it have some advantage?
Not really, it's just a little cleaner. % is the modular operator, used to calculate values that "wrap around" after a certain value (the "modulus"). The value is divided by the modulus, and the remainder is used as the result of the operation. The easiest way to explain is with some examples:

Code: Select all

 0 % 5 = 0
 1 % 5 = 1
 2 % 5 = 2
 3 % 5 = 3
 4 % 5 = 4
 5 % 5 = 0
 6 % 5 = 1
 7 % 5 = 2
 8 % 5 = 3
 9 % 5 = 4
10 % 5 = 0
11 % 5 = 1
12 % 5 = 2
13 % 5 = 3...
The result is exactly the same as what you have, so it's really up to your preference which one to use. :)
Saiho wrote:Also, some feeds don't give a description variable. Is there a simple way to make the description meter not show at all if it has nothing to display?
You could add this to the script, I suppose. At the bottom of the Output() function, do something like:

Code: Select all

if Queue['Item1Desc'] == '' then
    SKIN:Bang('!HideMeterGroup', 'GroupName')
end
User avatar
Saiho
Posts: 46
Joined: September 24th, 2012, 2:11 pm

Re: Reader

Post by Saiho »

As much as lua terrifies me, I'll give it a try. Thank you so much for the help!
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Reader

Post by Kaelri »

Saiho wrote:As much as lua terrifies me, I'll give it a try.
I assure you, that's always the first step to falling in love with it. :)
User avatar
Saiho
Posts: 46
Joined: September 24th, 2012, 2:11 pm

Re: Reader

Post by Saiho »

Teehee ok, that was fun!
After managing to completely break the script, I figured out where to insert your code. But, once I switch to a feed without description, it hides descriptions for all the other feeds too. So I changed it to this:

Code: Select all

	if Queue['Item1Desc'] == '' then
    SKIN:Bang('!HideMeterGroup', 'gDesc')
	else 
	SKIN:Bang('!ShowMeterGroup', 'gDesc')
	end
Seems to be working as I want, but a confirmation that it's the right way to do it would be nice.

And another thing that came up now. Do the variables the script generates get transferred with @Include? I'm trying to use #CurrentFeed# in a skin that includes the reader, but it doesn't seem to know what I'm talking about. Is that normal or have I mistyped something?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Reader

Post by Kaelri »

Saiho wrote:Teehee ok, that was fun!
After managing to completely break the script, I figured out where to insert your code. But, once I switch to a feed without description, it hides descriptions for all the other feeds too. So I changed it to this:

Code: Select all

	if Queue['Item1Desc'] == '' then
		SKIN:Bang('!HideMeterGroup', 'gDesc')
	else 
		SKIN:Bang('!ShowMeterGroup', 'gDesc')
	end
Seems to be working as I want, but a confirmation that it's the right way to do it would be nice.
Yep, that looks right. :)
Saiho wrote:And another thing that came up now. Do the variables the script generates get transferred with @Include? I'm trying to use #CurrentFeed# in a skin that includes the reader, but it doesn't seem to know what I'm talking about. Is that normal or have I mistyped something?
Any skin that is actually running the Reader script should have the variable. It is a dynamic variable, so make sure you have DynamicVariables=1 wherever you're trying to use it.