It is currently May 2nd, 2024, 4:26 am

TrayMeasure question

Get help with creating, editing & fixing problems with skins
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: TrayMeasure question

Post by Kaelri »

Alright. There are a couple of issues with the script. The most likely source of your problem is this:

Code: Select all

while true do
As you probably know, this means that unless it matches one of your conditions and returns, the while-loop will simply never end, and therefore neither will the Update() function. The problem is that Rainmeter requires the Update() function to complete itself and return a value. The function is called at a regular rate of once per second, so Rainmeter is already doing what you want to do. To put it another way, you can think of Update() itself as your while-loop.

The second thing that jumps out at me is the StatusFilePath variable. Backslash is an escape character in Lua strings, so you just need to double them up.

Code: Select all

'C:\\Users\\Mike\\Documents\\Rainmeter\\Skins\\SageTV\\SageTV\\ParserStatus.xml'
EDIT: If you want to make this a little easier, you can also use Rainmeter's built-in variables to get to your skins library Actually, turns out you can't use the SKIN object at all in a TrayMeasure context. Nevermind.

EDIT 2: Two other little things I found. First, you're missing a second "=" on line 16:

Code: Select all

if updateCounter == 0 then
And second, you need to cast AlertStatus as a number before you can do math on it.

Code: Select all

      AlertStatus=string.match(ReadContent, '<AlertStatus>(.-)</>') or 'Batch AlertStatus match.'
      AlertStatus=tonumber(AlertStatus)
Mike
Posts: 12
Joined: September 25th, 2012, 1:17 am

Re: TrayMeasure question

Post by Mike »

The endless loop is intentional... eventually one of the args to the if-then-else cascade will match and it will end...

I fixed '=' problem (a common mistake for me!), the double-backslash thing, and I added tonumber(AlertStatus).

Now it loads and runs! I have a few issues to fix, but at least I'm getting something being printed to the log now.

Thanks! I suppose the lua file just wasn't loading and there wasn't any error being written to the log?
Mike
Posts: 12
Joined: September 25th, 2012, 1:17 am

Re: TrayMeasure question

Post by Mike »

Update: Made a couple more minor changes and now the script is generating the correct return values... now all I have to do is create icons and I'll be done!
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: TrayMeasure question

Post by Kaelri »

Mike wrote:Thanks! I suppose the lua file just wasn't loading and there wasn't any error being written to the log?
Or it was hitting some sort of fundamental error while it was defining the script from the file, before it even got to the point of executing functions.

Anyway, glad you've made some progress. I hope you'll let us know how it works out. We're all kind of intrigued by this project over here; I think you may be the first person ever to use a Lua script in a tray measure. :)
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: TrayMeasure question

Post by jsmorley »

Kaelri wrote: Or it was hitting some sort of fundamental error while it was defining the script from the file, before it even got to the point of executing functions.

Anyway, glad you've made some progress. I hope you'll let us know how it works out. We're all kind of intrigued by this project over here; I think you may be the first person ever to use a Lua script in a tray measure. :)
Ever....
Mike
Posts: 12
Joined: September 25th, 2012, 1:17 am

Re: TrayMeasure question

Post by Mike »

Well, I'm close to having my skin finished, and I'll be sure to post it, especially since I borrowed a lot of code from both of you. It won't be much use to anyone that doesn't have their own SageTV server, but it could probably be modified to use with MythTV or other PC-based PVR software.
Mike
Posts: 12
Joined: September 25th, 2012, 1:17 am

Re: TrayMeasure question

Post by Mike »

Still not quite there. While I believe the script is generating correct return values, I'm not getting the right icons to display.

To simplify things, I changed the end of the TrayMeasure.lua to just cycle through valid return values, like so:

Code: Select all

	iconCounter=iconCounter+1
	if iconCounter>5 then iconCounter=0 end
	print('Icon '..iconCounter)
	return iconCounter
end
The debug log shows that the value of iconCounter is cycling from 0 to 5 and back to zero, as expected.

My TrayMeasure is now this:

Code: Select all

[TrayMeasure]
Measure=Script
ScriptFile=C:\Users\Mike\Documents\Rainmeter\Skins\SageTV\SageTV\TrayMeasure.lua
TrayMeter=Bitmap
TrayBitmap=\SageTV\Images\TrayIcons\%i.ico
What I think I should be seeing is each icon (0.ico, 1.ico, 2.ico... ) for one second. What I am getting is 1.ico for 1s followed by 5.ico for about 5s. It seems that if iconCounter is 0, I get the icon 1.ico, and if it is anything greater than zero, I get 5.ico.

Any ideas?
Mike
Posts: 12
Joined: September 25th, 2012, 1:17 am

Re: TrayMeasure question

Post by Mike »

Nevermind... I think I've figured it out. Looks like I need to put in MinValue and MaxValue.
Mike
Posts: 12
Joined: September 25th, 2012, 1:17 am

Re: TrayMeasure question

Post by Mike »

One (last?) problem.

Everything works fine when I hard-code the path for the statusfile, but that's not particularly user friendly. So I changed TrayMeasure:

Code: Select all

[TrayMeasure]
Measure=Script
StatusFile=#SKINSPATH#SageTV\SageTV\ParserStatus.xml
MaxValue=6
MinValue=1
ScriptFile=#SKINSPATH#SageTV\SageTV\TrayMeasure.lua
TrayMeter=Bitmap
TrayBitmap=\SageTV\Images\TrayIcons\%i.ico
and then in the lua script, I do:

Code: Select all

function readStatusFromFile()
	-- DETERMINE FILEPATH
	
	print('Calling GetOption.')
	StatusFile = SELF:GetOption('StatusFile')
	
This crashes Rainmeter... :( Is the SELF handle invalid? If so, is there another way for me to tell the script where to find the file? Or do I have a stupid syntax error somewhere?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: TrayMeasure question

Post by Kaelri »

Unfortunately, it does seem that SELF won't work in this context. This is a flaw resulting from the fact that we never anticipated using Lua in a TrayMeasure. This may be fixed in a future version, but for now you'll probably need to hard-code it.