It is currently July 19th, 2024, 12:33 am

Lua Scripting - How to include variables.inc to script.lua

Discuss the use of Lua in Script measures.
User avatar
Kurou
Posts: 42
Joined: January 24th, 2022, 2:54 pm
Location: World Wide Web

Re: Lua Scripting - How to include variables.inc to script.lua

Post by Kurou »

balala wrote: May 23rd, 2023, 7:08 pm Not sure if you are still interested in taking over the variables into the script (to be honest I didn't read all your discussion with Yincognito), but if you are, here is an example on how can you use a loop in the lua script, to take over the numbered variables. In the posted code, you have the PageColor1, ..., PageColor6 variables, which are six same named, but numbered variables. To take them over in the lua script file, you can use the following loop:

Code: Select all

function Initialize()
	Col = {}
	for i=1, 6 do
		Col[i] = SKIN:GetVariable('PageColor'..i)
	end
	SKIN:Bang('!SetVariable', 'Valami', Col[5])
end
As you can see I created a Col array, initially declared as being empty (Col = {}). Then a for cycle is used to populate the elements of this array with the PageColorX variables, taken by the GetVariable functions.
When you took over the variables you can use them as the elements of the array. For instance the first color is referred in the script as Col[1].
Sorry if you are not interested anymore in this, or the problem has been solved by Yincognoto or yourself.
Its good but my naming convention of variables is not like Var1=value but rather function/name=value. But still its a good idea if i would use Var1, Var2, etc.
Brought to you by: https://kurou.dev/
User avatar
Yincognito
Rainmeter Sage
Posts: 7742
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua Scripting - How to include variables.inc to script.lua

Post by Yincognito »

Kurou wrote: May 24th, 2023, 2:52 pm You have right, for example i could do settings, customization of my suite with !SetVariable and every time panel (which is used to control everything) will save those variables to file. It could be the best way to handle saving users settings. But i haven't testet !SetVariable enough to be sure that it will save and load every new value of the variables in memory. This way i could make this suite much more efficient and get rid off uneccessery write/read from disk.

What you think about it?
Sorry for the delay in responding, I've been busy with other stuff in the meantime.

The !SetVariable bang will not "save and load every new value of the variables in memory" - it isn't a mass saver / loader of variables like your Lua scripts attempt to. It simply sets any individual variable that you like to a new value, and that value will be available once you update / redraw stuff in the skin that uses it. It can even set a variable in a skin of your choosing via its Config parameter, i.e. the variable doesn't necessarily have to be from the current skin. So, for example, you can do [!SetVariable SomeVariable SomeValue "illustro\Clock"] to set SomeVariable to SomeValue in the Clock skin from the Illustro suite, no matter what skin you're doing this from. !SetVariable has nothing to do with the .inc files and won't change them or any file for that matter, it simply changes the value of a variable in a skin that is currently loaded (i.e. cached in memory).

For your settings panel, you could place some button called let's say "Save" that will write all variables to the .inc file via your mass saver script measure. You could have another button let's say "Apply" that will only set the desired variables in the skins and update/redraw the said skins accordingly without saving anything to the .inc. My point was that you don't need to write stuff to the .inc to immediately benefit from the new values of the variables in the current session (like you thought earlier), setting a variable already does the latter. Of course, if you're sure you really want to write to the .inc and refresh things to another session, you can implement just the "Save" button above.
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Kurou
Posts: 42
Joined: January 24th, 2022, 2:54 pm
Location: World Wide Web

Re: Lua Scripting - How to include variables.inc to script.lua

Post by Kurou »

Yincognito wrote: May 25th, 2023, 12:59 am Sorry for the delay in responding, I've been busy with other stuff in the meantime.

The !SetVariable bang will not "save and load every new value of the variables in memory" - it isn't a mass saver / loader of variables like your Lua scripts attempt to. It simply sets any individual variable that you like to a new value, and that value will be available once you update / redraw stuff in the skin that uses it. It can even set a variable in a skin of your choosing via its Config parameter, i.e. the variable doesn't necessarily have to be from the current skin. So, for example, you can do [!SetVariable SomeVariable SomeValue "illustro\Clock"] to set SomeVariable to SomeValue in the Clock skin from the Illustro suite, no matter what skin you're doing this from. !SetVariable has nothing to do with the .inc files and won't change them or any file for that matter, it simply changes the value of a variable in a skin that is currently loaded (i.e. cached in memory).

For your settings panel, you could place some button called let's say "Save" that will write all variables to the .inc file via your mass saver script measure. You could have another button let's say "Apply" that will only set the desired variables in the skins and update/redraw the said skins accordingly without saving anything to the .inc. My point was that you don't need to write stuff to the .inc to immediately benefit from the new values of the variables in the current session (like you thought earlier), setting a variable already does the latter. Of course, if you're sure you really want to write to the .inc and refresh things to another session, you can implement just the "Save" button above.
I understand !SetVariable just set's one variable not all of them, i was saying that i could do changing something in settings etc. will only !SetVariable for certain things and when users closes the panel via button or any other way, the variables which were set would be written to the *.inc file. So in short the same what you said :). (But im lazy, will i do it?)
Brought to you by: https://kurou.dev/
User avatar
Yincognito
Rainmeter Sage
Posts: 7742
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua Scripting - How to include variables.inc to script.lua

Post by Yincognito »

Kurou wrote: May 25th, 2023, 11:06 am I understand !SetVariable just set's one variable not all of them, i was saying that i could do changing something in settings etc. will only !SetVariable for certain things and when users closes the panel via button or any other way, the variables which were set would be written to the *.inc file. So in short the same what you said :). (But im lazy, will i do it?)
Ah, I see - sounds about right, but of course, laziness is an obstacle. I prefer to call it "mood" though. :lol:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
balala
Rainmeter Sage
Posts: 16399
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Lua Scripting - How to include variables.inc to script.lua

Post by balala »

Kurou wrote: May 25th, 2023, 11:06 am and when users closes the panel via button or any other way, the variables which were set would be written to the *.inc file.
If by "panel" you mean skin (am not sure), you should take a look to the OnCloseAction option, which can be added to the [Rainmeter] section of your skin. This option is executed when you unload the skin or close Rainmeter and could be used to physically save those variables.
User avatar
Yincognito
Rainmeter Sage
Posts: 7742
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Lua Scripting - How to include variables.inc to script.lua

Post by Yincognito »

balala wrote: May 25th, 2023, 12:01 pm If by "panel" you mean skin (am not sure), you should take a look to the OnCloseAction option, which can be added to the [Rainmeter] section of your skin. This option is executed when you unload the skin or close Rainmeter and could be used to physically save those variables.
Yep, that covers the close scenario well. Unfortunately, for the refresh scenario there isn't a clear and direct way to do it, since stuff is executed in those bangs after the first update following the refresh, and not before (like the on close does for closing). There are ways to "hack" it by using RightMouseUpAction=[...write stuff...][!ShowMenu], but they're not exactly user friendly, not to mention that they won't work if by any chance the user refreshes the skin from the Manage Rainmeter window and not via a skin's context menu (or even if he refreshes stuff via bangs and wants the writing process to happen automatically as a consequence without having to add the bangs there). That's would be a good topic for a suggestion for Rainmeter, to have an OnBeforeRefresh option, or even to merge the "close" part of the refresh into the existing OnCloseAction... :confused:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth