Greetings!
I try to make my mind around how the skin-ini and lua communicating.
More exactly i try to pass a dynamic variable to lua to process changes without refreshing my skin.
Whatever i tried, didn't worked. Tried to changed the value under [Variables], no changes in lua.
Tried also under the ScriptMeasure's MyOption, and tried changing that option with !SetOption Bang, but still not changed in Lua.
What i want to achieve is this:
- There is a variable in the INI file
- Get that variable's value in LUA
- Changing the value of the variable in the INI file
- Get the changed value in the LUA
Achieving this without any refreshing of the INI file. (if possible)
It is currently April 25th, 2024, 5:19 pm
Basics of variables exchanging
-
- Rainmeter Sage
- Posts: 276
- Joined: February 17th, 2014, 12:39 pm
- Location: Hungary
-
- Posts: 826
- Joined: November 20th, 2012, 11:58 pm
Re: Basics of variables exchanging
Please, post a sample skin/code
-
- Rainmeter Sage
- Posts: 16169
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Basics of variables exchanging
Posting a sample code, as FreeRaider asked would definitely be a good idea, however I can say some generalities:
You also have to create a Script measure, which will handle the lua code:
Now you can even process this value: (add this command after the previous one). This command will add 2 to the gotten variable.
If the variable is changing in the ini file, the lua script will get automatically the changed value (see immediately).
Very important here is the DynamicVariables=1 option. Without this, the string meter can't properly get the variable, changed dynamically by the lua script.
The whole codes:
.ini:
Change.lua:
Place this script to the @Resources folder.
Please let me know if this answer your question.
Eg, let's say, you have the following variable, defined in the [Variables] section of your skin:rbriddickk84 wrote:What i want to achieve is this:
- There is a variable in the INI file
...
Code: Select all
[Variables]
MyVar=24
Code: Select all
[MeasureLuaScript]
Measure=Script
ScriptFile=#@#Change.lua
About the lua code you have to know that it has two very important functions, Initialize() and Update(). Initialize() is executed once, immediately after you're refreshing your skin, while Update() is executed on each update cycle of the skin. To get the value of the variable into the lua code, add the following command to the Update() function: MyVar = tonumber(SKIN:GetVariable('MyVar')). The SKIN:GetVariable('MyVar')) expression gets the variable, while the tonumber() function converts this gotten value, to a number.rbriddickk84 wrote:What i want to achieve is this:
...
- Get that variable's value in LUA
...
Now you can even process this value:
Code: Select all
MyVar = MyVar + 2
If the variable is changing in the ini file, the lua script will get automatically the changed value (see immediately).
Now the last thing would be to transfere the processed variable back to the ini file. This will be done for example by the following command (add this after the previous command): SKIN:Bang('!SetVariable', 'NewVar', MyVar). See that the value of the MyVar variable will be transferred to the NewVar variable, which can be used into the ini file, eg in the following String meter:rbriddickk84 wrote:What i want to achieve is this:
...
- Get the changed value in the LUA
Code: Select all
[MeterVariables]
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##CRLF##NewVar#
DynamicVariables=1
Now one more: to see how the dynamic change works, you have to add eg a LeftMouseUpAction=[!SetVariable MyVar "(#MyVar#+1)"] option to the [MeterVariables] string meter. This way you're dynamically changing the value of the variable and the processed NewVar will follow the change, through the lua script.rbriddickk84 wrote:What i want to achieve is this:
...
- Changing the value of the variable in the INI file
The whole codes:
.ini:
Code: Select all
[Rainmeter]
Update=1000
[Variables]
MyVar=24
[MeasureLuaScript]
Measure=Script
ScriptFile=#@#Change.lua
[MeterVariables]
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##CRLF##NewVar#
DynamicVariables=1
LeftMouseUpAction=[!SetVariable MyVar "(#MyVar#+1)"]
Code: Select all
function Initialize()
end
function Update()
MyVar = tonumber(SKIN:GetVariable('MyVar'))
MyVar = MyVar + 2
SKIN:Bang('!SetVariable', 'NewVar', MyVar)
end
Please let me know if this answer your question.
-
- Rainmeter Sage
- Posts: 276
- Joined: February 17th, 2014, 12:39 pm
- Location: Hungary
Re: Basics of variables exchanging
Okay, i wrote one quickly here, my code is very chaotic to paste in here.FreeRaider wrote:Please, post a sample skin/code
INI code:
Code: Select all
[Rainmeter]
Update=1000
AccurateText=1
[Variables]
CalYear=0
[DateYear]
Measure=Time
Format=%G
OnUpdateAction=[!SetOption "CalendScript" "MyYear" "[DateYear]"][!SetVariable CalYear "[DateYear]"]
[CalendScript]
Measure=Script
ScriptFile="#CURRENTPATH#@Resources\Scripts\calendar.lua"
MyYear=2000
DynamicVariables=1
UpdateDivider=-1
Code: Select all
function Initialize()
idYear = SELF:GetOption('MyYear', 'n/a')
idSecYear = SKIN:GetVariable('CalYear', 'n/a')
end
function Update()
print(idYear)
print(idSecYear)
end -- function Update
-
- Rainmeter Sage
- Posts: 276
- Joined: February 17th, 2014, 12:39 pm
- Location: Hungary
Re: Basics of variables exchanging
Thank you balala, i saw your post after i posted mine.
I posted an example code Sorry about it, i wasn't at my computer for awhile.
I just wanted to get the LUA script the changed value without refreshing the skin ini.
To be honest, what you wrote that all i know already. But thank you for your help
I posted an example code Sorry about it, i wasn't at my computer for awhile.
I just wanted to get the LUA script the changed value without refreshing the skin ini.
To be honest, what you wrote that all i know already. But thank you for your help
-
- Rainmeter Sage
- Posts: 16169
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Basics of variables exchanging
You don't even have to. See below.rbriddickk84 wrote:I just wanted to get the LUA script the changed value without refreshing the skin ini.
Please forgive me, but it seems you don't! I say that because you've placed the GetOption and GetVariable into the Initialize() function, which, as I wrote above, is executed just once, when you're refreshing your skin. That's why they can't get the newly set values. Just move them into the Update() function. This is the main problem.rbriddickk84 wrote:To be honest, what you wrote that all i know already. But thank you for your help
I also would have something to say about how you're returning the processed values from the lua script to the skin: I usually always try to avoid using the print function. In my opinion a much - much better alternative would be to transfere these values back through some SKIN:Bang('!SetVariable', 'VariableName', Value), or SKIN:Bang('!SetOption', 'SectionName', 'OptionName', Value) commands. Will avoid a lot of headaches.
-
- Rainmeter Sage
- Posts: 276
- Joined: February 17th, 2014, 12:39 pm
- Location: Hungary
Re: Basics of variables exchanging
It's okay, but i still say, i do know, but only that one thing i missed! To be precise.
But anyway, i see now where i was mistaken, and i should have figured it out by myself, because that is a minor thing, so i was incredibly blind! xD
Thank you very much for pointing that out, and for the help!
But anyway, i see now where i was mistaken, and i should have figured it out by myself, because that is a minor thing, so i was incredibly blind! xD
Thank you very much for pointing that out, and for the help!
-
- Rainmeter Sage
- Posts: 16169
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Basics of variables exchanging
I hope I didn't offend you, because I didn't want to. Sorry if however I did. Please forgive me...rbriddickk84 wrote:It's okay, but i still say, i do know, but only that one thing i missed! To be precise.
But anyway, i see now where i was mistaken, and i should have figured it out by myself, because that is a minor thing, so i was incredibly blind! xD
Thank you very much for pointing that out, and for the help!
But, I still have a two comments:
- NEVER, but never use the @Resources folder as ScriptFile="#CURRENTPATH#@Resources\Scripts\calendar.lua" ([CalendScript] measure). We never are refering to this folder with a #CURRENTPATH#@Resources\ statement, even if this is correct and works well, instead we're using the #@# statement. Details: https://forum.rainmeter.net/viewtopic.php?p=119247#p119247
- Also although this is not a huge mistake, you shouldn't include the paths into quotations (ScriptFile option of the [CalendScript] measure): https://forum.rainmeter.net/viewtopic.php?p=137628#p137628
-
- Rainmeter Sage
- Posts: 276
- Joined: February 17th, 2014, 12:39 pm
- Location: Hungary
Re: Basics of variables exchanging
Hey, don't worry, it's okay I wasn't that thorough while reading your answer, and slipped over details, so my bad!balala wrote:I hope I didn't offend you, because I didn't want to. Sorry if however I did. Please forgive me...
I use the @Resources folder like that, because my skin is currently part of a parent skin group. So this is in the AstroTech4 folder, where there is also a @Resources folder. But when i finished with the project, i will change the code back to #@#.balala wrote:But, I still have a two comments:
- NEVER, but never use the @Resources folder as ScriptFile="#CURRENTPATH#@Resources\Scripts\calendar.lua" ([CalendScript] measure). We never are refering to this folder with a #CURRENTPATH#@Resources\ statement, even if this is correct and works well, instead we're using the #@# statement. Details: https://forum.rainmeter.net/viewtopic.php?p=119247#p119247
- Also although this is not a huge mistake, you shouldn't include the paths into quotations (ScriptFile option of the [CalendScript] measure): https://forum.rainmeter.net/viewtopic.php?p=137628#p137628
Because when i am finished, i will make this skin a standalone skin, outside of AstroTech4 folder.
And i removed the quotations, just to be sure
Again, thanks for your help mate!