It is currently March 9th, 2021, 10:30 am
Discuss the use of Lua in Script measures.
dvo
Posts: 1029 Joined: February 7th, 2016, 6:08 am
Post
by dvo » May 15th, 2016, 12:05 pm
balala i found a little mistake had to befixed in lua : in english we say half past 9 for 9:30 in dutch we say half ten
is it possible to add a +1 in hour on half time?
like this it had to be : kwarter past 9 , half ten , kwarter to ten .... 10 o' clock
Code: Select all
function Initialize()
afterText = SKIN:GetVariable('AfterText')
untilText = SKIN:GetVariable('UntilText')
halfText = SKIN:GetVariable('HalfText')
AlarmTime = SKIN:GetVariable('Time')
numTable = {}
numTable['0'] = 'nul'
numTable['1'] = 'een'
numTable['2'] = 'twee'
numTable['3'] = 'drie'
numTable['4'] = 'vier'
numTable['5'] = 'vijf'
numTable['6'] = 'zes'
numTable['7'] = 'zeven'
numTable['8'] = 'acht'
numTable['9'] = 'negen'
numTable['10'] = 'tien'
numTable['11'] = 'elf'
numTable['12'] = 'twaalf'
numTable['13'] = 'dertien'
numTable['14'] = 'veertien'
numTable['15'] = 'kwart'
numTable['16'] = 'zestien'
numTable['17'] = 'zeventien'
numTable['18'] = 'achttien'
numTable['19'] = 'negentien'
numTable['30'] = 'half'
end
function Update()
AlarmTime = SKIN:GetVariable('Time')
LenAlarmTime = string.find(AlarmTime, ':') - 1
hour = tonumber(string.sub(AlarmTime, 1, LenAlarmTime))
if hour > 12 then
hour = hour - 12
end
minute = tonumber(string.sub(AlarmTime, -2, -1))
if minute < 30 then
adjustedMinute = minute
midText = afterText
elseif minute == 30 then
adjustedMinute = minute
midText = halfText
else
midText = untilText
adjustedMinute = 60 - minute
hour = hour == 12 and 1 or hour + 1
end
if adjustedMinute >= 20 and adjustedMinute < 30 then
if adjustedMinute == 20 then
minuteText = 'twintig minuten'
else
minuteText =numTable[tostring(adjustedMinute - 20)]..' en twintig minuten'
end
else
if adjustedMinute ~= 15 and adjustedMinute ~= 45 and adjustedMinute ~= 30 then
if adjustedMinute == 1 then
minuteText = numTable[tostring(adjustedMinute)]..' minuut'
else
minuteText = numTable[tostring(adjustedMinute)]..' minuten'
end
else
minuteText = numTable[tostring(adjustedMinute)]
end
end
if adjustedMinute == 0 then
return numTable[tostring(hour)]..' uur'
else
return minuteText.. ' '..midText..' '..numTable[tostring(hour)]
end
end
Last edited by dvo on May 15th, 2016, 12:14 pm, edited 1 time in total.
balala
Rainmeter Sage
Posts: 12354 Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania
Post
by balala » May 15th, 2016, 12:11 pm
Please upload the last package you have. I worked in the meantime with those skins and it would be useful to have a "clean" package. Thanks.
EDIT: Sorry, you've edited your post in the meantime. It's ok.
dvo
Posts: 1029 Joined: February 7th, 2016, 6:08 am
Post
by dvo » May 15th, 2016, 12:15 pm
this is the altered version of jsmorley and the addon of yours ... you want the clean version of jsmorley?
balala
Rainmeter Sage
Posts: 12354 Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania
Post
by balala » May 15th, 2016, 12:17 pm
dvo wrote: this is the altered version of jsmorley and the addon of yours ... you want the clean version of jsmorley?
No, no at all. As I posted in the EDIT, it's ok now.
balala
Rainmeter Sage
Posts: 12354 Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania
Post
by balala » May 15th, 2016, 12:35 pm
dvo wrote: balala i found a little mistake had to befixed in lua : in english we say half past 9 for 9:30 in dutch we say half ten
is it possible to add a +1 in hour on half time?
like this it had to be : kwarter past 9 , half ten , kwarter to ten .... 10 o' clock
The same situation we have in Hungarian. So, here is what to do: just add the
hour = hour == 12 and 1 or hour + 1 line under the elseif statement in the Update() function:
Code: Select all
if minute < 30 then
adjustedMinute = minute
midText = afterText
elseif minute == 30 then
adjustedMinute = minute
midText = halfText
hour = hour == 12 and 1 or hour + 1
else
midText = untilText
adjustedMinute = 60 - minute
hour = hour == 12 and 1 or hour + 1
end
dvo
Posts: 1029 Joined: February 7th, 2016, 6:08 am
Post
by dvo » May 15th, 2016, 12:45 pm
like this? is doesn't change any thing here ...yet
Code: Select all
function Initialize()
afterText = SKIN:GetVariable('AfterText')
untilText = SKIN:GetVariable('UntilText')
halfText = SKIN:GetVariable('HalfText')
AlarmTime = SKIN:GetVariable('Time')
numTable = {}
numTable['0'] = 'nul'
numTable['1'] = 'een'
numTable['2'] = 'twee'
numTable['3'] = 'drie'
numTable['4'] = 'vier'
numTable['5'] = 'vijf'
numTable['6'] = 'zes'
numTable['7'] = 'zeven'
numTable['8'] = 'acht'
numTable['9'] = 'negen'
numTable['10'] = 'tien'
numTable['11'] = 'elf'
numTable['12'] = 'twaalf'
numTable['13'] = 'dertien'
numTable['14'] = 'veertien'
numTable['15'] = 'kwart'
numTable['16'] = 'zestien'
numTable['17'] = 'zeventien'
numTable['18'] = 'achttien'
numTable['19'] = 'negentien'
numTable['30'] = 'half'
end
function Update()
AlarmTime = SKIN:GetVariable('Time')
LenAlarmTime = string.find(AlarmTime, ':') - 1
hour = tonumber(string.sub(AlarmTime, 1, LenAlarmTime))
if hour > 12 then
hour = hour - 12
end
minute = tonumber(string.sub(AlarmTime, -2, -1))
if minute < 30 then
adjustedMinute = minute
midText = afterText
elseif minute == 30 then
adjustedMinute = minute
midText = halfText
else
midText = untilText
adjustedMinute = 60 - minute
hour = hour == 12 and 1 or hour + 1
if minute < 30 then
adjustedMinute = minute
midText = afterText
elseif minute == 30 then
adjustedMinute = minute
midText = halfText
hour = hour == 12 and 1 or hour + 1
else
midText = untilText
adjustedMinute = 60 - minute
hour = hour == 12 and 1 or hour + 1
end
if adjustedMinute >= 20 and adjustedMinute < 30 then
if adjustedMinute == 20 then
minuteText = 'twintig minuten'
else
minuteText =numTable[tostring(adjustedMinute - 20)]..' en twintig minuten'
end
else
if adjustedMinute ~= 15 and adjustedMinute ~= 45 and adjustedMinute ~= 30 then
if adjustedMinute == 1 then
minuteText = numTable[tostring(adjustedMinute)]..' minuut'
else
minuteText = numTable[tostring(adjustedMinute)]..' minuten'
end
else
minuteText = numTable[tostring(adjustedMinute)]
end
end
if adjustedMinute == 0 then
return numTable[tostring(hour)]..' uur'
else
return minuteText.. ' '..midText..' '..numTable[tostring(hour)]
end
end
balala
Rainmeter Sage
Posts: 12354 Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania
Post
by balala » May 15th, 2016, 12:57 pm
dvo wrote: like this? is doesn't change any thing here ...yet
No, at all. You've copied the whole
Code: Select all
if minute < 30 then
...
elseif minute == 30 then
...
else
...
end
statement again, but forgot to add the last end command. I doubt the code you've posted could work.
Here is the TextClock.lua:
Code: Select all
function Initialize()
afterText = SKIN:GetVariable('AfterText')
untilText = SKIN:GetVariable('UntilText')
halfText = SKIN:GetVariable('HalfText')
AlarmTime = SKIN:GetVariable('Time')
numTable = {}
numTable['0'] = 'nul'
numTable['1'] = 'een'
numTable['2'] = 'twee'
numTable['3'] = 'drie'
numTable['4'] = 'vier'
numTable['5'] = 'vijf'
numTable['6'] = 'zes'
numTable['7'] = 'zeven'
numTable['8'] = 'acht'
numTable['9'] = 'negen'
numTable['10'] = 'tien'
numTable['11'] = 'elf'
numTable['12'] = 'twaalf'
numTable['13'] = 'dertien'
numTable['14'] = 'veertien'
numTable['15'] = 'kwart'
numTable['16'] = 'zestien'
numTable['17'] = 'zeventien'
numTable['18'] = 'achttien'
numTable['19'] = 'negentien'
numTable['30'] = 'half'
end
function Update()
hour = tonumber(os.date('%I'))
minute = tonumber(os.date('%M'))
if minute < 30 then
adjustedMinute = minute
midText = afterText
elseif minute == 30 then
adjustedMinute = minute
midText = halfText
hour = hour == 12 and 1 or hour + 1
else
midText = untilText
adjustedMinute = 60 - minute
hour = hour == 12 and 1 or hour + 1
end
if adjustedMinute >= 20 and adjustedMinute < 30 then
if adjustedMinute == 20 then
minuteText = 'twintig minuten'
else
minuteText =numTable[tostring(adjustedMinute - 20)]..' en twintig minuten'
end
else
if adjustedMinute ~= 15 and adjustedMinute ~= 45 and adjustedMinute ~= 30 then
if adjustedMinute == 1 then
minuteText = numTable[tostring(adjustedMinute)]..' minuut'
else
minuteText = numTable[tostring(adjustedMinute)]..' minuten'
end
else
minuteText = numTable[tostring(adjustedMinute)]
end
end
if adjustedMinute == 0 then
return numTable[tostring(hour)]..' uur'
else
return minuteText.. ' '..midText..' '..numTable[tostring(hour)]
end
end
dvo
Posts: 1029 Joined: February 7th, 2016, 6:08 am
Post
by dvo » May 15th, 2016, 1:08 pm
this is now the full working version
mixed both scripts and it works now
You do not have the required permissions to view the files attached to this post.
dvo
Posts: 1029 Joined: February 7th, 2016, 6:08 am
Post
by dvo » May 15th, 2016, 1:24 pm
balala
Rainmeter Sage
Posts: 12354 Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania
Post
by balala » May 15th, 2016, 1:28 pm
Yes, you was right that I forgot to replace some lines in the original script. But I'm glad if finally you could make it to work well.