It depends on what exactly is the use case, of course - you know better than us what you're aiming for in your suite. The skin(s) can be slower for various number of reasons, and most of them can be solved or alleviated through a better structure and handling of the things within, or adjusting various small details in the code.
It is currently October 13th, 2024, 8:39 am
Lua Scripting - How to include variables.inc to script.lua
-
- Rainmeter Sage
- Posts: 8442
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Lua Scripting - How to include variables.inc to script.lua
-
- Posts: 42
- Joined: January 24th, 2022, 2:54 pm
- Location: World Wide Web
Re: Lua Scripting - How to include variables.inc to script.lua
Im going to use *.inc files in the skins and handle all of the modification of the variables in the *.lua files. I think its not that bad idea, and probably yeah it will work with some extreme tinkering but won't that be a fun journey to learn lua?
For now i know that it will load all variables from the files even if i want to change single variable. That would be the main problem but still, its usefull.
For now i know that it will load all variables from the files even if i want to change single variable. That would be the main problem but still, its usefull.
Brought to you by: https://kurou.dev/
-
- Rainmeter Sage
- Posts: 8442
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Lua Scripting - How to include variables.inc to script.lua
For sure - just take care to not make it too fun...
If you're only changing variables from Lua, without having to write them on the disk, there's no need to parse the .inc apart from the skin load / refresh time (the Initialize() function).
-
- Posts: 42
- Joined: January 24th, 2022, 2:54 pm
- Location: World Wide Web
Re: Lua Scripting - How to include variables.inc to script.lua
If i wont save those variables back to disk they will be lost on the exit of the skin or refresh.Yincognito wrote: ↑May 22nd, 2023, 9:12 pm For sure - just take care to not make it too fun...
If you're only changing variables from Lua, without having to write them on the disk, there's no need to parse the .inc apart from the skin load / refresh time (the Initialize() function).
Brought to you by: https://kurou.dev/
-
- Rainmeter Sage
- Posts: 8442
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Lua Scripting - How to include variables.inc to script.lua
Not necessarily. You could save them to disk periodically, or even in an OnCloseAction in the [Rainmeter] section of your skin (or an OnRefreshAction, except that this will happen at the end of the update cycle after the refresh, not before the event, like the close action). Of course, the OnCloseAction is triggered only on "normal" unloading / closing, meaning that if you have a crash / hang or some other abnormal event, it won't happen - but it's an alternative that you should be aware of.
Folks typically write stuff to .incs right after changing the variable partly because it's the norm and partly to make sure they are saved if such an abnormal event happens, but that doesn't mean the alternative is not viable in a "standard usage" scenario. Obviously, the choice on whether to use it or not is yours - just thought you should know that there isn't just one way of doing things.
P.S. If you give it a shot, make sure you use some simple tests to play with those options a bit before actually using them, so that you understand exactly how they work.
-
- Posts: 42
- Joined: January 24th, 2022, 2:54 pm
- Location: World Wide Web
Re: Lua Scripting - How to include variables.inc to script.lua
In my case, writing to file is need. I want rainmeter to load new values as fast as possible after the change. If i wont write to file refreshing, redrawing etc wont update the variable unless its written to file then refresh etc.Yincognito wrote: ↑May 22nd, 2023, 10:31 pm Not necessarily. You could save them to disk periodically, or even in an OnCloseAction in the [Rainmeter] section of your skin (or an OnRefreshAction, except that this will happen at the end of the update cycle after the refresh, not before the event, like the close action). Of course, the OnCloseAction is triggered only on "normal" unloading / closing, meaning that if you have a crash / hang or some other abnormal event, it won't happen - but it's an alternative that you should be aware of.
Folks typically write stuff to .incs right after changing the variable partly because it's the norm and partly to make sure they are saved if such an abnormal event happens, but that doesn't mean the alternative is not viable in a "standard usage" scenario. Obviously, the choice on whether to use it or not is yours - just thought you should know that there isn't just one way of doing things.
P.S. If you give it a shot, make sure you use some simple tests to play with those options a bit before actually using them, so that you understand exactly how they work.
Brought to you by: https://kurou.dev/
-
- Rainmeter Sage
- Posts: 8442
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Lua Scripting - How to include variables.inc to script.lua
I believe you, but Rainmeter will, in fact, have the new values ready even without writing to an .inc, if you also use [!SetVariable ...], which modifies the value of the variable in memory (you can do that from Lua as well, by the way). What I'm saying is that if you save something like [!SetVariable SomeVar 5][!WriteKeyValue Variables SomeVar 5 "#@#Variables.inc"], the second part is pointless anyway until the skin is reloaded / refreshed, since SomeVar will already be 5 because of the first part. This means that you can update and redraw stuff using the new value without having to load it from disk every time.
Of course, if you refresh things, either by clicking or using a bang, the modified value will be lost, but then, there would be no reason to refresh via a bang because of the above, and writing to file before refreshing by click can be done using something like RightMouseUpAction=[do your writing process here][!SkinMenu] which will happen on every right click on some skin element of your choosing (or, alternatively, in the ContextActions from the [Rainmeter] section).
Anyway, as I said, in the end it's your decision, but I had the feeling that there was a bit of misunderstanding when it came to the variable handling above and wanted make things clearer.
-
- Rainmeter Sage
- Posts: 16651
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Lua Scripting - How to include variables.inc to script.lua
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
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.
-
- Rainmeter Sage
- Posts: 8442
- Joined: February 27th, 2015, 2:38 pm
- Location: Terra Yincognita
Re: Lua Scripting - How to include variables.inc to script.lua
Nah, for the last part we were just discussing the fact that writing variables to disk is actually needed only before refreshing / reloading the skin for some reason (and not necessarily each time such a variable is modified), since their changed values should be present in memory anyway without impeding any update / redraw that happens in the skin (assuming that plainly setting the variable was performed as well).
-
- Posts: 42
- Joined: January 24th, 2022, 2:54 pm
- Location: World Wide Web
Re: Lua Scripting - How to include variables.inc to script.lua
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.Yincognito wrote: ↑May 23rd, 2023, 8:13 pm Nah, for the last part we were just discussing the fact that writing variables to disk is actually needed only before refreshing / reloading the skin for some reason (and not necessarily each time such a variable is modified), since their changed values should be present in memory anyway without impeding any update / redraw that happens in the skin (assuming that plainly setting the variable was performed as well).
What you think about it?
Brought to you by: https://kurou.dev/