It is currently October 21st, 2021, 5:17 am

Need help to merge two lua Scripts

Discuss the use of Lua in Script measures.
User avatar
Indy
Posts: 40
Joined: August 8th, 2013, 10:40 pm

Need help to merge two lua Scripts

Post by Indy »

Hello,

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
Positiv things:

- 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
Positiv things:

- 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
User avatar
thatsIch
Posts: 446
Joined: August 7th, 2012, 9:18 pm

Re: Need help to merge two lua Scripts

Post by thatsIch »

So I am not sure how we can help you. What would the output be of this so-called 'Merge'?
User avatar
Indy
Posts: 40
Joined: August 8th, 2013, 10:40 pm

Re: Need help to merge two lua Scripts

Post by Indy »

Hello,

i looking for merge this two scripts to on countdown script where do follow:

- If the lua have no or fals input Rainmeter simple should do nothing. (No errors, no crash or something)
- Give the countdown to seperate strings for seperat Meters (Day, Hour, Minutes, Seconds)
- If the countdown is runing end it give a Text out (example: Countdown Complete).

Whit other words, integrate the positiv things of both scripts in one.
I do not know how to describe it differently.

greeting
User avatar
thatsIch
Posts: 446
Joined: August 7th, 2012, 9:18 pm

Re: Need help to merge two lua Scripts

Post by thatsIch »

just alter the first script and add

"... or 0" after each number

that will prevent the error. And the second script does not mention a complete anywhere. It must be done in the ini itself you are using. Even without, just check all 4 variables for 0 and then set the textfield of your choice to "complete" and all other to "".