It is currently May 25th, 2019, 4:19 pm

Can script measure have different number and string values?

Discuss the use of Lua in Script measures.
rxtd
Posts: 95
Joined: April 30th, 2017, 11:51 am

Can script measure have different number and string values?

rxtd » August 30th, 2018, 6:43 am

I want a script measure to have some not zero number value and a string value that is not a number. Just like every plugin can have.
I see that there is a deprecated function GetStringValue that should allow script to have different values. Documentation page states that this function is still supported.
I also found an old forum thread that has an example of a script in "deprecated" style:

Code: Select all

function Initialize()
   -- do something here
end

function Update()
   -- do something here
end

function GetStringValue()
   return "Hello world!"
end

function GetValue()
   return 42
end
First post in that thread also states:
for backwards compatibility, GetStringValue() is called if Update() does not return any value
I created a simple skin to test it and it doesn't seem to work.

Code: Select all

[script]
measure=script
ScriptFile=test.lua

[back]
meter=image
h=30
w=100
solidcolor=888888
Both values of a Script measure is 0.

So, has the support for this been removed, or do I have some errors in my code?

My Rainmeter version is 4.2.0 r3111 (Jul 8 2018).
Last edited by rxtd on August 30th, 2018, 10:06 pm, edited 2 times in total.
User avatar
balala
Rainmeter Sage
Posts: 8210
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can script meter have different number and string values?

balala » August 30th, 2018, 7:41 am

Pack please the whole config (containing both the .ini and the .lua files, and/or other eventually needed files as well) and upload it here, to can check.
rxtd
Posts: 95
Joined: April 30th, 2017, 11:51 am

Re: Can script meter have different number and string values?

rxtd » August 30th, 2018, 8:13 am

balala, the whole config is two files, code of which I have already posted.
But here you go.
You do not have the required permissions to view the files attached to this post.
User avatar
FreeRaider
Posts: 779
Joined: November 20th, 2012, 11:58 pm

Re: Can script meter have different number and string values?

FreeRaider » August 30th, 2018, 8:41 am

And what would be your goal?

To see "Hello world" and/or "42"?
rxtd
Posts: 95
Joined: April 30th, 2017, 11:51 am

Re: Can script meter have different number and string values?

rxtd » August 30th, 2018, 8:48 am

FreeRaider wrote:And what would be your goal?

To see "Hello world" and/or "42"?
In this example: to just see both values. One as a number, one as a string.

In real life: for example, to have number value indicate if something is working and a string value as a result of work.
Or to have a raw number value and a formatted in some way string value.
Or to have two different number values (Rainmeter can transparently use numbers in string as just numbers) without having to manage variables.
User avatar
FreeRaider
Posts: 779
Joined: November 20th, 2012, 11:58 pm

Re: Can script meter have different number and string values?

FreeRaider » August 30th, 2018, 8:57 am

Maybe this:

Code: Select all

[MeterText]
Meter=String
FontSize=20
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[&script:GetStringValue()]#CRLF#[&script:GetValue()]
DynamicVariables=1
Have a look at inline lua
User avatar
jsmorley
Developer
Posts: 19245
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Can script meter have different number and string values?

jsmorley » August 30th, 2018, 1:47 pm

Forget about GetValue() and GetStringValue(), those are not helpful in this case, as they are working in the opposite direction. They are used in Lua to get the value of a measure from the skin, not the other way around.

A Lua measure can't return both a number and string value at the same time, so the right answer is Inline Lua.

This doesn't mean that you have to create and call a function() in in the Lua, as the normal Update() function can do any work you want, and set any values you want for both numbers and strings. Then you could for instance have the "return" set the measure value to some number variable, that you use in the skin with MeasureName on a meter, and at the same time use an Inline Lua section variable to retrieve the string value at the point in the skin where you want to use it, presumably in the Text option of a String meter.

https://docs.rainmeter.net/manual/lua-scripting/inline-lua/#RetrievingAVariable

Skin:

Code: Select all

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

[Lua]
Measure=Script
ScriptFile=Test.lua

[MeterLua]
Meter=String
MeasureName=Lua
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=The number is %1, and the string is [&Lua:myString]
Test.lua:

Code: Select all

function Update()

	myString = 'One, Two, Three'
	return 123

end
1.jpg
BTW, the subject line of this post should be "Can script measure have different number and string values?" This is an important distinction, as it is always the first step to understand the difference between a meter and a measure.
You do not have the required permissions to view the files attached to this post.
rxtd
Posts: 95
Joined: April 30th, 2017, 11:51 am

Re: Can script measure have different number and string values?

rxtd » August 30th, 2018, 8:12 pm

FreeRaider, jsmorley, thank you for you answers. I guess, inline lua is exactly what I needed. I don't know how could I miss it.
jsmorley wrote:Forget about GetValue() and GetStringValue(), those are not helpful in this case, as they are working in the opposite direction. They are used in Lua to get the value of a measure from the skin, not the other way around.
Actually, I think they are. Or, to be correct, they were.
I didn't mean to use it as "measureHandle:GetStringValue()". Documentation and that old post say that I can write a global function named GetStringValue in .lua file, and this function will be used to obtain string value of a script measure. It has been about 7 years since it become deprecated though.
Initial question was about "Why doesn't it work as documentation says?"

Code: Select all

function GetStringValue()
This function was used to set the script measure's value.
I guess that with inline lua this is not needed anymore, but I still think that it is strange: backward compatibility, and all that.
jsmorley wrote:BTW, the subject line of this post should be "Can script measure have different number and string values?" This is an important distinction, as it is always the first step to understand the difference between a meter and a measure.
Wow, I didn't think I could make such mistake.
Thank you for you correction, I fixed the title.
User avatar
FreeRaider
Posts: 779
Joined: November 20th, 2012, 11:58 pm

Re: Can script measure have different number and string values?

FreeRaider » August 30th, 2018, 10:24 pm

Glad if I helped.
User avatar
jsmorley
Developer
Posts: 19245
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Can script measure have different number and string values?

jsmorley » August 30th, 2018, 10:38 pm

rxtd wrote: Actually, I think they are. Or, to be correct, they were.
I didn't mean to use it as "measureHandle:GetStringValue()". Documentation and that old post say that I can write a global function named GetStringValue in .lua file, and this function will be used to obtain string value of a script measure. It has been about 7 years since it become deprecated though.
Initial question was about "Why doesn't it work as documentation says?"
I guess that with inline lua this is not needed anymore, but I still think that it is strange: backward compatibility, and all that.
That old form of GetValue() and GetStringValue() was used very early on in Lua in Rainmeter, before we implemented the more proper return function. In any case only one of them could be used, and a measure could only, and still can only, return a single value.