I am new to Rainmeter and wish to write a desktop memo. I plan to mix up the Input Text plugin and use Lua to write it into a TXT file. However, as I followed the documentation of Rainmeter I met some problems with Lua scripting. Can someone please help me fix it?
#Modification(should have stated the question clearer): The typer functions alright, I can change the text and the variable 'FirstVar' in Type_History.inc is changed accordingly as well. However, the TXT file I intend to modify stays blank. So I guess there was something wrong with the Lua code.
I realized that the variable #FirstVar is placed in a different file. Will this prevent lua obtaining it?
function Initialize()
filePath = SKIN:MakePathAbsolute(SELF:GetOption('OutputFile'))
end
function Update()
end
function Store(stringarg)
local File = io.open(filePath , 'a+')
File:write(stringarg)
File:close()
end
Last edited by NEPTUNIUMLI on June 2nd, 2021, 12:39 pm, edited 2 times in total.
CodeCode wrote: ↑June 2nd, 2021, 7:08 am
Try converting all of your files to UTF-8
Sometimes that creates issues.
But that is just a shot in the dark.
I have my skin.ini/inc documents in UTF16 LE, and the same for my .lua scripts. I do have the txt file in utf8 encoding, but nothing changed. No text appeared in the text document.
I checked the RM documentation for this issue so I guess I've followed orders?
Reading and writing external Unicode files in Lua
As noted above, you must always save the Lua script .lua file encoded as UTF-16 to use Unicode with Lua and Rainmeter. However, there may be times you want to read or write to external files from your Lua script. If you want to use Unicode with these external files, things have to be handled in a particular way.
I mentioned earlier that Lua always treats text as 8-bit single-byte characters. What the means in this context is that in effect Lua "internally" views all text as UTF-8, even though we always have the .lua file encoded as UTF-16 to work with Rainmeter. So Lua requires that any text file it reads or creates itself be encoded in UTF-8 to handle Unicode characters properly.
NEPTUNIUMLI wrote: ↑June 2nd, 2021, 6:19 am
I am new to Rainmeter and wish to write a desktop memo. I plan to mix up the Input Text plugin and use Lua to write it into a TXT file. However, as I followed the documentation of Rainmeter I met some problems with Lua scripting. Can someone please help me fix it?
----------------------------------------------redundant functions... remove them if you have no use of them
function Initialize()
filePath = SKIN:MakePathAbsolute(SELF:GetOption('OutputFile'))
end
function Update()
end
----------------------------------------------
function Store(stringarg)
local filePath = SKIN:MakePathAbsolute(SELF:GetOption('OutputFile'))
local File = io.open(filePath , 'a+')
File:write(stringarg)
File:close()
SKIN:Bang('!WriteKeyValue', 'Variables', 'FirstVar', stringarg, SKIN:GetVariable('CURRENTPATH')..'Type_History.inc')
SKIN:Bang('!Refresh')
end
----------------------------------------------redundant functions... remove them if you have no use of them
function Initialize()
filePath = SKIN:MakePathAbsolute(SELF:GetOption('OutputFile'))
end
function Update()
end
----------------------------------------------
function Store(stringarg)
local filePath = SKIN:MakePathAbsolute(SELF:GetOption('OutputFile'))
local File = io.open(filePath , 'a+')
File:write(stringarg)
File:close()
SKIN:Bang('!WriteKeyValue', 'Variables', 'FirstVar', stringarg, SKIN:GetVariable('CURRENTPATH')..'Type_History.inc')
SKIN:Bang('!Refresh')
end
Second way is optional.
Thank you but I think that may not be where the problem is because the typer built on my desktop runs pretty smoothly. The TXT modification function is where I encountered a problem.
I tried the code suggested but the txt file is still unmodified
NEPTUNIUMLI wrote: ↑June 2nd, 2021, 12:34 pm
Thank you but I think that may not be where the problem is because the typer built on my desktop runs pretty smoothly. The TXT modification function is where I encountered a problem.
I tried the code suggested but the txt file is still unmodified
In that case you have to use "a" mode of file I/O.
function Store(stringarg)
local filePath = SKIN:MakePathAbsolute(SELF:GetOption('OutputFile'))
local File = io.open(filePath , 'a')
local time = os.date("%Y-%m-%d")
local Hour = os.date("%H")
File:write("\n")
File:write(time.." Hour"..Hour.." ---- "..stringarg)
File:close()
end