It is currently March 28th, 2024, 1:48 pm

Mph to kph

Discuss the use of Lua in Script measures.
Post Reply
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Mph to kph

Post by PtitChat107 »

Hi,
I actively monitor volcanic and seismic activities using this skin, I would like to find a way to automatically convert the speed data of thunderstorms into kilometers per hour. I know the formula is: kph=(mph*1,60934) but could not find where to place this change in the file "StormFetch.lua" :???:
User avatar
jsmorley
Developer
Posts: 22628
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Mph to kph

Post by jsmorley »

Change this:

Code: Select all

			if string.match(sItem, sPatternStormWind) then
				tWind[i] = string.match(sItem, sPatternStormWind)
				windSpeed = tonumber(string.match(tWind[i], '(.-) MPH'))
				tWind[i] = math.round((windSpeed * 1.60934))..' KPH'
				tMoving[i] = string.match(sItem, sPatternStormMoving)
			else
And add this at the bottom:

Code: Select all

function math.round(num, idp)
	assert(tonumber(num), 'Round expects a number.')
	
	local mult = 10 ^ (idp or 0)
	if num >= 0 then
		return math.floor(num * mult + 0.5) / mult
	else
		return math.ceil(num * mult - 0.5) / mult
	end
	
end
1.png
PtitChat107
Posts: 126
Joined: December 31st, 2015, 6:40 pm

Re: Mph to kph

Post by PtitChat107 »

Thank you Jsmorley, that's exactly what I wanted ! :)
Post Reply