It is currently May 23rd, 2024, 11:42 am

Check if a variable was changed

Discuss the use of Lua in Script measures.
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Check if a variable was changed

Post by AlC »

Hey,

like the title said it, how can I check if a variable was changed.
So let's say I get a variable via SKIN:GetVariable('...') and now I want to check if the value is different like the value of the previous update.

Example lua:

Var= SKIN:GetVariable('SomeVar')

if Var ~= Var(previous) then ...

Any help would be nice.
Rainmeter - You are only limited by your imagination and creativity.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Check if a variable was changed

Post by Kaelri »

Here's a method I use very frequently:

Code: Select all

function Initialize()
    LastValue = nil
end

function Update()
    local CurrentValue = SKIN:GetVariable('SomeVar')
    if CurrentValue ~= LastValue then
        LastValue = CurrentValue
        -- do other stuff
    end
end
User avatar
AlC
Posts: 329
Joined: June 9th, 2011, 6:46 pm

Re: Check if a variable was changed

Post by AlC »

Thanks Kaelri !

I had this in my mind but I couldn't strangely convert the !SetVariable-bang (from my mind) into Lua ... God! :headbang:

And you should add this code with a little sentence here.
Rainmeter - You are only limited by your imagination and creativity.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Check if a variable was changed

Post by Kaelri »

Ah, good idea. :) I'd forgotten about that thread.