i have two luas where make a countdown. Both have good and bad things, and i would really appreciate if anyone can help me.
Countdown1.lua
Code: Select all
PROPERTIES = {year=0, month=0, day=0, hour=0, minute=0, second=0}
function Initialize()
stringDate = tolua.cast(SKIN:GetMeter("Date"), "CMeterString")
stringHour = tolua.cast(SKIN:GetMeter("Hour"), "CMeterString")
stringMinute = tolua.cast(SKIN:GetMeter("Minute"), "CMeterString")
stringSecond = tolua.cast(SKIN:GetMeter("Second"), "CMeterString")
end -- function Initialize
function Update()
local rLeft = os.time(PROPERTIES) - os.time()
local dLeft = math.floor((rLeft/60/60+2)/24) --day, change the +2 to whatever you need depending on your location compared to iceland. Hour difference + or -
local hLeft = math.floor(rLeft/60/60+2)%24 --hour, change the +2 to whatever you need depending on your location compared to iceland. Hour difference + or -
local mLeft = math.floor(rLeft/60)%60 --minute
local sLeft = math.floor(rLeft)%60 --second
stringDate:SetText(dLeft)
stringHour:SetText(hLeft)
stringMinute:SetText(mLeft)
stringSecond:SetText(sLeft)
end -- function Update
- give the countdown to seperate strings for seperat Meters (Day, Hour, Minutes, Seconds)
Negative things:
- If the lua have no or fals input Rainmeter give every second an error (Script: CountDown1.lua:15: field 'day' missing in date table) an then after few second Rainmeter crash.
- Give not a Text if the countdown at 0, the Countdown running continuing whit a minus sign bevor the showing time.
Countdown2.lua
Code: Select all
PROPERTIES = {year=0, month=0, day=0, hour=0, min=0, sec=0, fintext=""}
function Initialize()
RELEASEDATE = {}
setmetatable(RELEASEDATE, getmetatable(PROPERTIES))
for k,v in pairs(PROPERTIES) do
if k ~= fintext then
RELEASEDATE[k] = v
end
end
RELEASEDATE.isdst = true
RELEASETEXT = PROPERTIES.fintext or ""
end
function GetTimeLeft()
local dif = os.time(RELEASEDATE) - os.time()
local timeleft = {
[1] = math.floor((dif/60/60+2)/24), --day, change the +2 to whatever you need depending on your location compared to iceland. Hour difference + or -
[2] = math.floor(dif/60/60+2)%24, --hour, change the +2 to whatever you need depending on your location compared to iceland. Hour difference + or -
[3] = math.floor(dif/60)%60, --minute
[4] = math.floor(dif)%60 --second
}
local text = {}
for i=1, #timeleft do
if i == 1 then
if timeleft[i] > 0 then
table.insert(text,timeleft[i])
end
else
table.insert(text,timeleft[i])
end
end
if dif <= 0 then
text = RELEASETEXT
else
text = table.concat(text,":")
end
return tostring(text)
end
function Update()
end
function GetStringValue()
return GetTimeLeft()
end
- If the lua have no or fals input Rainmeter do nothing. (No errors, no crash or something)
- If the countdown is runing end it give a Text (Complete) out.
Negative things:
- give not seperate strings for seperat Meters. All in one String (Day:Hour:Minutes:Seconds)
Now the Question,
i haven't got a clue about this kind of scripting and need anyone who help me merge the good things from both lua scripts in one, and remove the errors.
greeting and thanks for your effort