It is currently April 27th, 2024, 11:21 pm

Bug or Expected? - Lua Initialize(), Disabled=1

Report bugs with the Rainmeter application and suggest features.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Bug or Expected? - Lua Initialize(), Disabled=1

Post by KreAch3R »

Hello guys,

I noticed today that the Initialize function was called, while the Lua measure is disabled from the beginning. From the manual:
Disabled
If set to 1, the measure is never updated.
function Initialize()
Initialize is called once when the skin is refreshed or activated.
Does this mean that Initialize will be called regardless of Disabled value? A test skin for quick testing is attached. Please move it anywhere else if it doesn't fit this category.

Skin.ini:

Code: Select all

[Lua]
Measure=SCRIPT
ScriptFile=Test.lua
Disabled=1

[Meter]
Meter=IMAGE
SolidColor=100,0,0
W=40
H=40
Lua:

Code: Select all

function Initialize()

	print('Should I print, while I am disabled?')

end --function Initialize
You do not have the required permissions to view the files attached to this post.
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
smurfier
Moderator
Posts: 1931
Joined: January 29th, 2010, 1:43 am
Location: Willmar, MN

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by smurfier »

I believe this is expected behavior.

While a Disabled measure is never updated, it still needs to be initialized so that it exists.
GitHub | DeviantArt | Tumblr
This is the song that never ends. It just goes on and on my friends. Some people started singing it not knowing what it was, and they'll continue singing it forever just because . . .
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by jsmorley »

Correct. As I understand it, Initialize() is only run once on refresh, and not on !EnableMeasure. This is desirable behavior in my view.
User avatar
MerlinTheRed
Rainmeter Sage
Posts: 889
Joined: September 6th, 2011, 6:34 am

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by MerlinTheRed »

Is there a difference in behavior between Disabled=1 and UpdateDivider=-1?
Have more fun creating skins with Sublime Text 2 and the Rainmeter Package!
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by jsmorley »

MerlinTheRed wrote:Is there a difference in behavior between Disabled=1 and UpdateDivider=-1?
Yes. in the context of Lua, When a skin is loaded or refreshed, Disabled=1 runs Initialize() and nothing else. UpdateDivider=-1 runs Initialize(), then Update() once. Update() is not executed again unless you dynamically change UpdateDivider or use a !CommandMeasure.

The purpose of Initialize() in Lua is expressly to be something that is always, and only, run one time when the skin is loaded or refreshed. It is used to do things like set handles to measures, create tables, things you can and want to do one time, and not on each Update(). It would defeat the entire purpose of it to either not run it when the skin is loaded, or run it every time !EnableMeasure / !DisableMeasure is used.

UpdateDivider=-1 is expressly designed to allow you to run any measure "once", generally used to execute something like a measure getting your total hard drive space. Things that in the nature of them are not going to change while the skin is running.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by KreAch3R »

Aha, I see. I guess this happens with all measures that have Disabled=1, right? Some of their code is called, before stopping. So, disabling a measure doesn't really work as if the measure never existed in the .ini (or was commented out).
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by jsmorley »

KreAch3R wrote:Aha, I see. I guess this happens with all measures that have Disabled=1, right? Some of their code is called, before stopping. So, disabling a measure doesn't really work as if the measure never existed in the .ini (or was commented out).
Not sure I entirely follow, but in the context of measures other than Measure=Script, the entire measure will just not be executed on Disabled=1. Rainmeter will read the options of the measure, but that is about it. It won't "do anything" with the measure.

In the context of any Script measure(s), when the skin is loaded or refreshed, the Initialize() function of the .Lua will be executed once. Other than that, it is like any other measure, and will just be ignored when Disabled=1, so Update() will never be run.

UpdateDivider=-1 on any measure is just the same as saying UpdateDivider=Infinity. The measure will be fully executed one time, then sit at the bar in the Restaurant At The End Of the Universe, sipping a Pan Galactic Gargle Blaster, patiently waiting for the end of time before running again.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by KreAch3R »

You did follow :) . The reason I asked that second question is, that I have this weird error coming up, that I think it is related with Disabled (it doesn't include a Lua script).
In my suite's skin Actions, there is this part:

Code: Select all

[mWifiSSID]
Measure=PLUGIN
Plugin=WiFiStatus
WiFiInfoType=SSID
Substitute="0":"Not Connected"
Disabled=#Hide.Wifi#

[mWifiQuality]
Measure=PLUGIN
Plugin=WiFiStatus
WiFiInfoType=QUALITY
Disabled=#Hide.Wifi#

[mWifi%]
Measure=CALC
Formula=mWifiQuality
MaxValue=101
MinValue=0
Disabled=#Hide.Wifi#
I have it disabled, because my PC is wire-connected to the router. Whenever the skin is refreshed, though, this error pops up:

I tried to create an example skin, to see if I can replicate it, but I can't. The error doesn't appear anymore. The strange part is, that it doesn't appear in my Actions skin, either!

If I unload the example skin, the error reappears :confused: :

Code for the example skin:

Code: Select all

[Rainmeter]
Update=1000
Author=

[Metadata]
Name=
Information=
Version=
License=

[Variables]
Hide.Wifi=0

[mWifiSSID]
Measure=PLUGIN
Plugin=WiFiStatus
WiFiInfoType=SSID
Substitute="0":"Not Connected"
Disabled=#Hide.Wifi#

[mWifiQuality]
Measure=PLUGIN
Plugin=WiFiStatus
WiFiInfoType=QUALITY
Disabled=#Hide.Wifi#

[mWifi%]
Measure=CALC
Formula=mWifiQuality
MaxValue=101
MinValue=0
Disabled=#Hide.Wifi#

[Meter]
Meter=IMAGE
SolidColor=0,0,100
W=40
H=40
P.S: I' d like a Gargle Blaster, too! :D
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image
User avatar
jsmorley
Developer
Posts: 22631
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by jsmorley »

Not sure. Can't really test as I don't have WiFi on this computer.
User avatar
KreAch3R
Posts: 608
Joined: February 7th, 2011, 7:27 pm
Location: Thessaloniki, GR

Re: Bug or Expected? - Lua Initialize(), Disabled=1

Post by KreAch3R »

jsmorley wrote:Not sure. Can't really test as I don't have WiFi on this computer.
That's a plus, not a problem, as I don't have either. :) Should the error be produced if we don't have WiFi?
Inactive, due to life changes. Send me a PM for any question.

Desktop DeviartArt
Image