It is currently November 19th, 2018, 8:12 am

Access SELF & SKIN object!

Discuss the use of Lua in Script measures.
User avatar
CreativeMomoiro
Posts: 3
Joined: September 17th, 2018, 10:15 am

Access SELF & SKIN object!

CreativeMomoiro » September 17th, 2018, 10:34 am

Hi All

I have created a skin using lua script which I want to get MeasureScript options and update some Measure options value.
For example:

test.ini

Code: Select all

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

[MeasureScript]
Measure=Script
ScriptFile=test.lua
TestOption=Hello World
Disabled=1
UpdateDivider=-1
DynamicVariables=1


[MeasureString]
Measure=String
String=
DynamicVariables=1

[MeterBackground]
Meter=Image
W=520
H=30
SolidColor=52,55,63,255

[MeterTrendLabel]
Meter=String
MeasureName=MeasureString
X=260
Y=5
W=500
H=15
FontSize=11
FontColor=255,255,255,255
SolidColor=40,40,40,255
Padding=5,5,5,5
FontWeight=600
StringAlign=Center
test.lua

Code: Select all

function Initialize()

end

local data = SEFT:GetOption('TestOption')
SKIN:Bang('!SetOption', 'MeasureString', 'String', data)
SKIN:Bang('!UpdateMeasure', 'MeasureScript')
SKIN:Bang('!UpdateMeter', 'MeterTrendLabel')
SKIN:Bang('!Redraw')
But I got the error message: Script: test.lua:5: attempt to index global 'SEFT' (a nil value)
and also "Script: test.lua:5: attempt to index global 'SKIN' (a nil value)" when I tried to use SKIN object in script.

I could not figure it out :( , and looking for your support.
Many thanks.
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Access SELF & SKIN object!

balala » September 17th, 2018, 12:03 pm

CreativeMomoiro wrote:But I got the error message: Script: test.lua:5: attempt to index global 'SEFT' (a nil value)
and also "Script: test.lua:5: attempt to index global 'SKIN' (a nil value)" when I tried to use SKIN object in script.
There are a few issues with the posted code(s):
  • In the local data = SE[color=#FF0000]FT[/color]:GetOption('TestOption') line of the script code there is a miswriting: it should have to be local data = SE[color=#00AA00]LF[/color]:GetOption('TestOption'). Fix it.
  • I'm not sure how a standalone lua code works, but when used into a Rainmeter skin, you can't use the lines as you did. You have to include them into a function, like Initialize() or Update(). I suppose you wanted to include those lines into the Initialize() function, but finally you didn't. So include them:

    Code: Select all

    function Initialize()
    	local data = SELF:GetOption('TestOption')
    	SKIN:Bang('!SetOption', 'MeasureString', 'String', data)
    	SKIN:Bang('!UpdateMeasure', 'MeasureScript')
    	SKIN:Bang('!UpdateMeter', 'MeterTrendLabel')
    	SKIN:Bang('!Redraw')
    end
  • And finally don't update the [MeasureScript] Script measure of your code into the code of the .lua script itself. It!s not a good idea. Again I think what you wanted would be to update the [MeasureString] measure, not the [MeasureScript]. Am I right? If I am, here is the final update of the code:

    Code: Select all

    function Initialize()
    	local data = SELF:GetOption('TestOption')
    	SKIN:Bang('!SetOption', 'MeasureString', 'String', data)
    	SKIN:Bang('!UpdateMeasure', 'MeasureString')
    	SKIN:Bang('!UpdateMeter', 'MeterTrendLabel')
    	SKIN:Bang('!Redraw')
    end
User avatar
CreativeMomoiro
Posts: 3
Joined: September 17th, 2018, 10:15 am

Re: Access SELF & SKIN object!

CreativeMomoiro » September 17th, 2018, 3:33 pm

Thanks a lot for your help :) . I have changed the script as your suggest, it worked perfect :thumbup: .
Btw I want to get WebParser measure value in the script as below:

test.ini

Code: Select all

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

[MeasureScript]
Measure=Script
ScriptFile=test.lua
Disabled=1
UpdateDivider=-1
DynamicVariables=1

[MeasureSite]
Measure=WebParser
URL=http://ip-api.com/json/13.190.248.122
RegExp=(?s)(.*)
UpdateRate=3600
FinishAction=[&MeasureScript:setData()]

[MeterBackground]
Meter=Image
W=520
H=30
SolidColor=52,55,63,255

[MeterTrendLabel]
Meter=String
Text=
X=260
Y=5
W=500
H=15
FontSize=11
FontColor=255,255,255,255
SolidColor=40,40,40,255
Padding=5,5,5,5
FontWeight=600
StringAlign=Center
test.lua

Code: Select all

function Initialize()

end

function setData()

	MyMeasure = SKIN:GetMeasure('MeasureSite')

	SKIN:Bang('!SetOption', 'MeterTrendLabel', 'Text', MyMeasure::GetStringValue())
	SKIN:Bang('!UpdateMeter', 'MeterTrendLabel')
	SKIN:Bang('!Redraw')
end
But it didn't work. Although measure has value but the meter displayed nothing :(
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Access SELF & SKIN object!

balala » September 17th, 2018, 3:47 pm

CreativeMomoiro wrote:But it didn't work. Although measure has value but the meter displayed nothing :(
You've doubled the colon in the SKIN:Bang('!SetOption', 'MeterTrendLabel', 'Text', MyMeasure:[color=#FF0000]:[/color]GetStringValue()) line. Remove one of them: SKIN:Bang('!SetOption', 'MeterTrendLabel', 'Text', MyMeasure:GetStringValue())
User avatar
CreativeMomoiro
Posts: 3
Joined: September 17th, 2018, 10:15 am

Re: Access SELF & SKIN object!

CreativeMomoiro » September 17th, 2018, 4:00 pm

My bad :? Thanks for your help, greatly appreciated. :thumbup:
User avatar
balala
Rainmeter Sage
Posts: 7014
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Access SELF & SKIN object!

balala » September 17th, 2018, 4:02 pm

You're welcome.