It is currently March 28th, 2024, 8:00 am

Assigning measure return values to variables

Get help with creating, editing & fixing problems with skins
Post Reply
sunnys
Posts: 17
Joined: February 22nd, 2018, 6:31 pm

Assigning measure return values to variables

Post by sunnys »

I am currently trying to assign a measure to a variable but cannot seem to find a way to carry this out.

Below is my current code:

Code: Select all

[Rainmeter]
Update=40
AccurateText=1

[Variables]
GifFolder=blade_runner_car\
GifExtension=.gif
ArrowHeightMultuplier=2.5

;Counts gif snapshots
[ImageNumberCalc]
Measure=Calc
Formula=Counter % GifFolderImageCountSection

;Counts all gif parent folders
[GifFolderCountSection]
Measure=Plugin
Plugin=FolderInfo
Folder=#@#
InfoType=FolderCount
IncludeSubFolders=1
UpdateDivider=100

;Counts all gif images within gif folder
[GifFolderImageCountSection]
Measure=Plugin
Plugin=FolderInfo
Folder=#@#gifs\#GifFolder#
InfoType=FileCount
UpdateDivider=10

[GifSlideShow]
Meter=Image
ImagePath=#@#gifs\
ImageName=#GifFolder#frame_[ImageNumberCalc]#GifExtension#
AntiAlias=1
DynamicVariables=1
W=800
H=400
PreserveAspectRatio=1

;TODO: add all states and click action
[GifSlideShowArrowLeft]
Meter=Button
X=0
Y=([GifSlideShow:H] / #ArrowHeightMultuplier#)
ImagePath=#@#icons\
ButtonImage=arrow_left.png
ButtonCommand=

;TODO: add all states and click action
[GifSlideShowArrowRight]
Meter=Button
X=([GifSlideShow:W] - 60)
Y=([GifSlideShow:H] / #ArrowHeightMultuplier#)
ImagePath=#@#icons\
ButtonImage=arrow_right.png
ButtonCommand=["SomeCommand"]

[GifSlideshowNextScript]
Measure=Script
ScriptFile=testScript.lua
CurrentFolder=#GifFolder#
FolderCount=[GifFolderCountSection]
Test=#@#gifs\
I have used a script measure so that I can output items I want to be logged as I don't think they can be logged from within the config files.

My approach to this has been to get the current folder name/pos and get a count of all other folders and somehow increment a variable to contain the existing position of the master gif folder from within the images lie.

I initially tried to init the variable with reference to the measure but it always returns 0, I guess you cannot init variables with measures? So i need a way of calling the measure and storing the return in a variable so I can pick the next folder of images when the arrow is clicked.

Also any advice on how to better create a gif slideshow or general code comments are appreciated.
Attachments
MySkin.zip
(4.5 MiB) Downloaded 13 times
Last edited by sunnys on February 22nd, 2018, 7:29 pm, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Assigning measure return values to variables

Post by balala »

It is very hard for us to follow what's going on your skin, since we don't have nor the testScript.lua script file, nor the needed images. So, first please pack and upload the whole config (make sure to include the images, too).
sunnys
Posts: 17
Joined: February 22nd, 2018, 6:31 pm

Re: Assigning measure return values to variables

Post by sunnys »

balala wrote:It is very hard for us to follow what's going on your skin, since we don't have nor the testScript.lua script file, nor the needed images. So, first please pack and upload the whole config (make sure to include the images, too).
Attachment has been added of whole skin :)
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Assigning measure return values to variables

Post by balala »

sunnys wrote:I have used a script measure so that I can output items I want to be logged as I don't think they can be logged from within the config files.
If by config file you mean the .ini file of the skin, they can be, through the !Log bang. I think the only reason of the testScript.lua file is the log, so try to remove it and log from the skin itself.
sunnys
Posts: 17
Joined: February 22nd, 2018, 6:31 pm

Re: Assigning measure return values to variables

Post by sunnys »

balala wrote:If by config file you mean the .ini file of the skin, they can be, through the !Log bang. I think the only reason of the testScript.lua file is the log, so try to remove it and log from the skin itself.
I've added this to test it and the log reports the folder count properly.

Code: Select all

[GifSlideShowArrowLeft]
Meter=Button
X=0
Y=([GifSlideShow:H] / #ArrowHeightMultuplier#)
ImagePath=#@#icons\
ButtonImage=arrow_left.png
ButtonCommand=!Log [GifFolderCountSection] Warning
I now need to store the [GifFolderCountSection] in a variable, where would I do this automatically? In a calc measure?

What's the best way to then essentially choose the next folder of images? Could it be done in the .ini or with the help of lua?
User avatar
balala
Rainmeter Sage
Posts: 16109
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Assigning measure return values to variables

Post by balala »

sunnys wrote:I now need to store the [GifFolderCountSection] in a variable, where would I do this automatically? In a calc measure?
No you don't need a Calc measure, I think. When would you like to store the value? In the example below, the variable is stored when you click the left arrow (the same button as that which writes the log).

To permanently store the value of the measure (as a variable) you have to use the !WriteKeyValue bang. The following bang writes the current value of the measure as the MyVar variable into the [Variables] section: [!WriteKeyValue Variables MyVar "[GifFolderCountSection]"]. This bang has the only disadvantage that the skin won't be able to use the set value of the variable unless you're refreshing the skin.

To create a similar variable which can be dynamically used, you have to use the !SetVariable bang: [!SetVariable MyVar "[GifFolderCountSection]"]. Just take care that you have to add a DynamicVariables=1 option to each meter or measure where you want to use the dynamically set variable.

And finally you can use both bangs to do both: write the value of the variable into the [Variables] section and also set it dynamically, for an immediate utilization.
Eg complete the ButtonCommand option of the [GifSlideShowArrowLeft] Button meter as it follows:

Code: Select all

[GifSlideShowArrowLeft]
...
ButtonCommand=[!Log "[GifFolderCountSection] Warning"][!WriteKeyValue Variables MyVar "[GifFolderCountSection]"][!SetVariable MyVar "[GifFolderCountSection]"]
As I said, the !WriteKeyValue bang writes the new value immediately to the [Variables] section, while the !SetVariable bang sets it dynamically. This dynamically set new value can be displayed eg on a String meter (which have to have set the DynamicVariables=1 option - last option below):

Code: Select all

[MeterMyVar]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=MyVar: #MyVar#
DynamicVariables=1
sunnys wrote:What's the best way to then essentially choose the next folder of images? Could it be done in the .ini or with the help of lua?
Eg setting it through a !SetOption bang. In the following example the right arrow will switch to another folder (which you have to give in the bellow !SetOption bang):

Code: Select all

[GifSlideShowArrowRight]
...
ButtonCommand=['SetOption GifFolderCountSection Folder "The-Path-Of-The-New-Folder"][!UpdateMeasure "GifFolderCountSection"]
sunnys
Posts: 17
Joined: February 22nd, 2018, 6:31 pm

Re: Assigning measure return values to variables

Post by sunnys »

Hi,

Have an issue with I/O and getting a weird error when trying to run the code.

Code: Select all

Script: TestScript.lua:22: bad argument #1 to 'lines' (string expected, got userdata)
Attached is my updated code.

I am trying to run a lua function that opens a file and reads it line by line, but it's corrupted for some reason, however opening the file manually you can see all the information is there.
I might have a bunch of debug code in my project so try to ignore it as I'm trying to find a fix.
Attachments
MySkin.zip
Updated skin
(5.2 MiB) Downloaded 12 times
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Assigning measure return values to variables

Post by jsmorley »

I'm getting this error in the log:

Script: [string "scandir('C:\Users\Jeffrey\Documents\Rainmet..."]:1: attempt to call global 'scandir' (a nil value)

The start of the trouble is that you seem to be calling a function scandir() that I don't see existing anywhere in any of your code.
sunnys
Posts: 17
Joined: February 22nd, 2018, 6:31 pm

Re: Assigning measure return values to variables

Post by sunnys »

jsmorley wrote:I'm getting this error in the log:

Script: [string "scandir('C:\Users\Jeffrey\Documents\Rainmet..."]:1: attempt to call global 'scandir' (a nil value)

The start of the trouble is that you seem to be calling a function scandir() that I don't see existing anywhere in any of your code.
:jawdrop Oops, forgot to remove that.
Even after removing it still getting the same error, any suggestions?
Maybe it could be a file charset issue, as the plugin measure creates the file in utf-16 and I might need to read it in utf-8??

Edit: forgot to mention that I am using the MiddleMouseUpAction, the command triggered from there is what is causing my error.
sunnys
Posts: 17
Joined: February 22nd, 2018, 6:31 pm

Re: Assigning measure return values to variables

Post by sunnys »

I am now getting encoding issues with the file that gets created from the plugin measure.
When trying to read the file from lua I get gibberish like: line[1] ��b

When I change the encoding of the txt file to UTF-8/UTF-8 with BOM I get the correct output which is the txt file line by line being printed out.
My skin and lua script are both UTF-16.

When I try to modify the plugin measure to runcommand with an output of utf8 it still looks like gibberish.

What is going on here? What's the best way to read a txt file without having to manually change the encoding?

To test:
Use the middle click command on the right arrow

PS. I have removed a few gif folders as it makes the zip cumbersome, so if there are discrepancies between the gif output txt file and the gif folders, I wouldn't worry about it.
Attachments
MySkin.zip
(5.2 MiB) Downloaded 16 times
Post Reply