It is currently March 28th, 2024, 11:48 pm

Trying to change Drive option of measure using Bangs

Get help with creating, editing & fixing problems with skins
MarceloCLP
Posts: 3
Joined: May 6th, 2017, 4:28 am

Trying to change Drive option of measure using Bangs

Post by MarceloCLP »

My .ini looks like this.

Code: Select all

[DriveType]
Measure=FreeDiskSpace
Type=1
IgnoreRemovable=0
DynamicVariables=1

[Script]
Measure=Script
ScriptFile=D.lua

[MeterName]
Meter=String
X=0
Y=0
FontSize=20
My .lua file looks like this:

Code: Select all

function Initialize ()
    -- The current drives connected to the computer.
    -- 65 ~ 92
    Drives = {}
    DriveChecker = SKIN:GetMeasure("DriveType")
    for i = 65, 92 do
        CurrentDrive = string.char(i) .. ':'
        SKIN:Bang("!SetOption 'DriveType' 'Drive' " .. CurrentDrive)
        print(DriveChecker:GetOption("Drive"))
    end
end

function Update ()
end
The GetOption("Drive") should return a different value on each iteration of the for, but it only returns an empty string. The concatenation is correct, I checked that, and the script is also recognized properly by the .ini file. I am guessing I can change the Drive option using bangs? Or am I doing something wrong?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trying to change Drive option of measure using Bangs

Post by jsmorley »

I don't really understand what you are trying to do. That is going to always just set the value of the Drive option to ASCII 92 which is "\". That and the ":" you are concatenating, so Drive=\:.

I may be misunderstanding, but you can't do loops like that in Lua and have Rainmeter respond to the individual values as the loop is executed. The entire Update() function will be executed in full during a single skin Update cycle, and in an example like that, all you will see in the skin is the result of the last value set.
MarceloCLP
Posts: 3
Joined: May 6th, 2017, 4:28 am

Re: Trying to change Drive option of measure using Bangs

Post by MarceloCLP »

I think the problem is that it's not even changing the value of the drive. If I just set it outside of the for loop, using, let's say, "D:", and then retrieve the value of Drive from the measure, it will return an empty string as well.

The range I used is wrong, it should be [65, 90], so it will test each drive available, from A to Z. But it doesn't change anything as I explained above. :/
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trying to change Drive option of measure using Bangs

Post by jsmorley »

You have a couple of errors, but it will change the value of the Drive option on the measure.

If I change your .lua to:

Code: Select all

function Initialize ()
    -- The current drives connected to the computer.
    -- 65 ~ 92
    Drives = {}
    DriveChecker = SKIN:GetMeasure("DriveType")
    for i = 65, 90 do
        CurrentDrive = string.char(i) .. ':'
        SKIN:Bang('!SetOption', 'DriveType', 'Drive', CurrentDrive)
    end
end

function Update ()
end
Then the Drive option will be set to "Z:" and the measure returns "Removed". Since I don't have any Z: drive.

Note I changed "92" to "90", and you had a formatting issue with your SKIN:Bang command. Once I fix those it works fine.

Which it not to say it does anything useful mind you. As I said, it will ALWAYS be set to "Z:" and the loop is entirely pointless.

Your "print" statement" in the Lua is also pointless, as the initial value of the measure's Drive option is not set, or "". That is all that any GetOption will see in that loop. Remember the entire Initialize() function will be executed in full during the initial skin Update cycle. The !SetOption to set the Drive option on the measure will not be seen by the skin until the Lua is done, and the control is returned back to the skin.

I hope I'm being clear. I hate to see you go down a rabbit hole that won't get you anywhere. The sequence of events for this skin when it is loaded or refreshed will be:

1) Create all measures and meters.
2) Start the first Update cycle.
3) Get the value of the [DriveType] measure. That will be whatever the type of your "C:" drive is, as that is the default when there is no Drive option defined.
4) Execute the Lua script. The script will do whatever is defined in it, but NOTHING the script communicates to the skin will be seen until the Lua is done.
5) When control is returned from the Lua script, take any actions in bangs in the Lua and set the value of the script measure to any "return" value from the Lua's Update() function. This will set the Drive option of the [DriveType] measure to "Z:".
6) Update the single meter you have defined. It has nothing to display of course, I expect it is just there as a place-holder.
7) Draw the skin.
8) Go to 2).
MarceloCLP
Posts: 3
Joined: May 6th, 2017, 4:28 am

Re: Trying to change Drive option of measure using Bangs

Post by MarceloCLP »

I understand what you are saying. The idea behind this skin was to go through each letter in the alphabet, and retrieve the ones connected to your computer (local drives and usb drives). And then show information about them, without having to go to the skins and selecting which driver you want to use. That's boring :P

So, is there a way I can do this?
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Trying to change Drive option of measure using Bangs

Post by jsmorley »

MarceloCLP wrote:I understand what you are saying. The idea behind this skin was to go through each letter in the alphabet, and retrieve the ones connected to your computer (local drives and usb drives). And then show information about them, without having to go to the skins and selecting which driver you want to use. That's boring :P

So, is there a way I can do this?
Not easily. I guess You could have 26 measures and 26 meters in the skin, with all meters set to "Hidden=1". Then have the Lua script check the value of each measure one after the other. Do this in Update(), not Initialize(), so it will detect changes, like if you plug or unplug a USB drive.

If they are "Removable / Fixed / Network / CDRom / Ram" then send a bang to "unhide" that meter. If they are "Error / Removed", then leave the meter hidden, in fact explicitly set them to hidden, again, to react to changes.

Nothing you can do with a single measure and changing the Drive option is gong to be practical.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Trying to change Drive option of measure using Bangs

Post by balala »

Sorry jsmorley, you've posted your reply when I wrote mine, so finally I posted mine, too.

MarceloCLP, you have to know Rainmeter definitely isn't a programming language and although you can go through the letters of the alphabet with a lua script (lua being indeed a programming language), but the returned information can't be used into the skin, as you wanted. I understood what you tried to achieve, but I think that way it's impossible.
However a somehow similar approach could exist. A while ago I wrote a code, improved later by eclectic-tech. The skin shows only the connected drives, ignoring the non-existent and the removed ones. You can take a look here, respectively you can download the packed skin a few comments below.