Hi! Is there a way to calculate the letters in a random output string? I'm working on a quote skin that provides you with a new quote each day, and I need to know the number of letters in the string so that I can change the font size of the quote accordingly. Or does anyone know any other way for me to do it?
Thanks!!
It is currently April 28th, 2024, 12:13 pm
Calculating the letters in an output string
-
- Posts: 15
- Joined: June 10th, 2017, 10:54 am
- Location: India
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calculating the letters in an output string
You will need a very simple Lua script for this.
Skin:
Lua:
NOTE: This will NOT work right with multi-byte Unicode characters in your quotes. This might include some pictographic languages, and some symbols. The number that string.len() returns is the number of "bytes" in the string, and that can be off when some Unicode characters are used.
Skin:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
[MeasureQuote]
Measure=Plugin
Plugin=QuotePlugin
PathName=C:\Users\Jeffrey\Documents\Pithy\pithy.txt
UpdateDivider=5
OnUpdateAction=[!EnableMeasure MeasureScript][!UpdateMeasure MeasureScript]
[MeasureScript]
Measure=Script
ScriptFile=Test.lua
Disabled=1
UpdateDivider=1
[MeterQuote]
Meter=String
MeasureName=MeasureQuote
MeasureName2=MeasureScript
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=%1#CRLF#%2 characters
Code: Select all
function Initialize()
myMeasure = SKIN:GetMeasure('MeasureQuote')
end
function Update()
myQuote = myMeasure:GetStringValue()
return string.len(myQuote)
end
You do not have the required permissions to view the files attached to this post.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calculating the letters in an output string
This is a bit easier if you use the latest 4.1 beta of Rainmeter from https://www.rainmeter.net, since you can use Inline Lua to simplify things.
Skin:
Lua:
Skin:
Code: Select all
[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1
[Variables]
[MeasureQuote]
Measure=Plugin
Plugin=QuotePlugin
PathName=C:\Users\Jeffrey\Documents\Pithy\pithy.txt
UpdateDivider=5
[MeasureScript]
Measure=Script
ScriptFile=Test.lua
[MeterQuote]
Meter=String
MeasureName=MeasureQuote
FontSize=13
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
DynamicVariables=1
Text=%1#CRLF#That is [&MeasureScript:quoteChars] characters
Code: Select all
function Initialize()
myMeasure = SKIN:GetMeasure('MeasureQuote')
end
function Update()
myQuote = myMeasure:GetStringValue()
quoteChars = string.len(myQuote)
end
You do not have the required permissions to view the files attached to this post.
-
- Posts: 15
- Joined: June 10th, 2017, 10:54 am
- Location: India
Re: Calculating the letters in an output string
Thanks, it works perfectly now! I didn't really know what Lua scripting was earlier, so thank you for introducing me to it too. I'm sure it would come in handy.
-
- Developer
- Posts: 22631
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: Calculating the letters in an output string
Great. Glad to help.