It is currently June 26th, 2019, 4:47 pm

Mph to kph

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

Mph to kph

PtitChat107 » September 25th, 2017, 9:47 pm

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: 19272
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Mph to kph

jsmorley » September 25th, 2017, 10:15 pm

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
You do not have the required permissions to view the files attached to this post.
PtitChat107
Posts: 119
Joined: December 31st, 2015, 6:40 pm

Re: Mph to kph

PtitChat107 » September 26th, 2017, 8:15 am

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