Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 1491

Help: Rainmeter Skins • Re: Please tell me an example of luascript

$
0
0
Please tell me an example of luascript that erases the contents of a specific file. if this is possible.
It definitely is possible. For instance create the Script.lua file into the @Resources folder of your config (obviously you can use any valid name, just make sure to set the proper name in the [MeasureLuaScript] measure of yoru skin):

Code:

function EmptyFile(file)io.open(file,"w"):close()end
Create any kind of (simple) meter in your skin and add the following option to it: LeftMouseUpAction=[&MeasureLuaScript:EmptyFile('x://PathOfMyFile//MyFileToEmpty.txt')]. Make sure to replace the red path with the proper path of your file you want to empty through the lua script.
And also an example of writing to a file.
Add the following function to the previously created Script.lua file, beside the already existing EmptyFile function:

Code:

function WriteFile(file, stringTowrite)filewrite = io.open(file, "w")filewrite:write(stringTowrite)filewrite:close()end
Add the following RightMouseUpAction option to the same meter to which you've added the above LeftMouseUpAction: RightMouseUpAction=[&MeasureLuaScript:WriteFile('x://PathOfMyFile//MyFileToEmpty.txt', 'Text to be written into the file')]. Once again take care to replace the above red colored file path and name with the path and name of the file you'd like to alter with the lua script and the green text with the text you'd like to write into the file.
If you did this, when you left click the meter you've added the above two options to, the appropriate file is emptied, while when you right click it, the Text to be written into the file text is written to the file.
Obviously if you simply right click the meter (without left clicking it first), the Text to be written into the file string is written to the file, without emptying it first.

Please let me know if you can't get any of the above functions to work.

Statistics: Posted by balala — Today, 5:40 pm



Viewing all articles
Browse latest Browse all 1491

Trending Articles