It is currently June 25th, 2019, 12:24 am

lua question

Discuss the use of Lua in Script measures.
User avatar
dvo
Posts: 540
Joined: February 7th, 2016, 6:08 am

lua question

dvo » May 12th, 2016, 7:47 pm

maybe some one can help me with this lua isn't my thing ...
but i made a clock if you input text like 21:00 then press enter and press set timer
the clock moves to that time now i have included text time in to it and the lua was on os.dat(%I)...
but what it had to do is load the time and show text time .... :oops: all i get is nul uur :o
You do not have the required permissions to view the files attached to this post.
User avatar
balala
Rainmeter Sage
Posts: 8308
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

balala » May 12th, 2016, 8:14 pm

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
dvo
Posts: 540
Joined: February 7th, 2016, 6:08 am

Re: lua question

dvo » May 12th, 2016, 8:24 pm

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

Re: lua question

balala » May 12th, 2016, 8:32 pm

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
dvo
Posts: 540
Joined: February 7th, 2016, 6:08 am

Re: lua question

dvo » May 12th, 2016, 8:37 pm

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 ..
User avatar
FreeRaider
Posts: 781
Joined: November 20th, 2012, 11:58 pm

Re: lua question

FreeRaider » May 13th, 2016, 11:16 am

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

Re: lua question

balala » May 13th, 2016, 2:47 pm

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: 8308
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

balala » May 13th, 2016, 2:48 pm

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
dvo
Posts: 540
Joined: February 7th, 2016, 6:08 am

Re: lua question

dvo » May 13th, 2016, 4:27 pm

it works :) gonna test it all the way and lua is a script lang. i still not get..
but understand your explanation of it i did find it inpossible to rewrite it
tnx balala for your kind help again :)
User avatar
balala
Rainmeter Sage
Posts: 8308
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: lua question

balala » May 13th, 2016, 4:31 pm

You're welcome.