It is currently March 28th, 2024, 10:13 pm

lua question

Discuss the use of Lua in Script measures.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

There's a problem with the TextClock.lua file: this new file is not working well. I have a previous TextClock.lua, you've used before and that is 100% ok. You'll find it attached to this message. Just replace the existing file, with this one.
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

dvo wrote:then i have again what i don't want i guess it shows the time from the clock and not the time of the set timer ....
both will not work i know that the other one works couse it runs on os time and not on the set timer
what i'm trying to make is that the lua the time out of the set timer loads instead of the real time :-(
I suppose it's not impossible. If you won't find a solution, tomorrow I'll try to find one.
User avatar
FreeRaider
Posts: 826
Joined: November 20th, 2012, 11:58 pm

Re: lua question

Post by FreeRaider »

Out of curiosuty, can you post an example (a simple code or numerical) of what you want?
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

FreeRaider wrote:Out of curiosuty, can you post an example (a simple code or numerical) of what you want?
You'll find the skin in dvo's first post above.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

dvo wrote:lua had to be fixed couse lua says simply take the time of the operation system ....instead of hour and minutes out of the variable tried many ways but don't understand lua script yet ..
Here is the fix of your last problem. If you want that on the alarm clock the text indicate not the current time, but what you've set to the alarm, you'll have to work with the TextClock.lua. This file takes the hour and minute of the operating system and you'll want instead to take the Time variable from the Arc.ini and work with it. To achieve this, just replace the

Code: Select all

hour = tonumber(os.date('%I'))
minute = tonumber(os.date('%M'))
lines of the lua file (Update() function), with the following ones:

Code: Select all

	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))
In this code, the AlarmTime = SKIN:GetVariable('Time') line gets the Time variable from the main ini file. LenAlarmTime = string.find(AlarmTime, ':') - 1 determines the place of the character before the : (the last digit of the hour). You need this because the number of hours can have one or two digits and you have to know this to can read the hour.
The next step is to get from the alarmTime variable the number of hours and the number of minutes. hour = tonumber(string.sub(AlarmTime, 1, LenAlarmTime)) determines the hour, copying from the AlarmTime variable everything from the first, until the LenAlarmTime character (one or two characters). Also minute = tonumber(string.sub(AlarmTime, -2, -1)) copies the last two characters of AlarmTime. In both cases the copied characters are converted to numbers by the tonumber function.
The last thing you'll have to do, is to extract 12 from the number of hours, if this is greater then 12 (the lua script works only if the number of hours is below 12).
I left the rest of the TextClock.lua file untouched. It can use with no problems the hour and minute variables determined previously.
To be honest, I just believe this is a good solution, because I don't know Dutch at all, so I practically can't check. But I think it's a good solution. Please let me know if it indeed is.
Also note that with all this changes, you won't be able to use the TextClock.lua file into the TextClock.ini. If you want to use it, you'll have to recreate the initial TextClock.lua, name it for example TextClock2.lua and replace its name in the [MeasureTime] measure of the TextClock.ini.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

You're welcome.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

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.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

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.
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

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? :D

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
User avatar
balala
Rainmeter Sage
Posts: 16110
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

Post by balala »

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