I tested your lua script, and it seems to work for me.
I'm not sure if you are using this function as part of an Update lua script, or if you are using a !CommandMeasure. I chose to test it as an Update.
I was changing the Temp and Rain variables and refreshing the skin to test. I was getting the responses I thought it should give.
The logic seemed to work for me. I did change your "butand" language to make the sentence sound correct, but I did not change the logic.
I'm not sure if there is a "better way", but this seems to work.
Here the exact code of yours I tested.
Is this all correct, or am I missing something?
When I run it with 18 and Yes, it responds with:
You need a jacket and an umbrella would be useful.
test_weather.ini
Code: Select all
[Rainmeter]
Update=1000
[measureTempProcess]
Measure=Script
ScriptFile=test_weather.lua
Temp=18
Rain=Yes
[meterShowWxCondition]
Meter=String
MeasureName=measureTempProcess
X=10
Y=10
FontSize=12
FontColor=255,255,255,220
SolidColor=0,0,0,200
Padding=15,15,15,15
AntiAlias=1
Text=%1
test_weather.lua
Code: Select all
local function getMainString( temp, rain )
local negation = (temp > JACKET_LIMIT) and " don't" or ""
local outerwear = (temp < COAT_LIMIT) and "coat" or "jacket"
local butand = ((temp > JACKET_LIMIT) and (rain=="Yes")) and " but an" or ((temp <= JACKET_LIMIT) and (rain=="Yes") and " and an" or ".")
local umbrella = (rain=="Yes") and "umbrella would be useful." or ""
return string.format("You%s need a %s%s %s", negation, outerwear, butand, umbrella)
end
function Update()
JACKET_LIMIT = 20
COAT_LIMIT = 10
sTemp = SELF:GetOption('Temp')
nTemp = tonumber(sTemp)
sRain = SELF:GetOption('Rain')
return getMainString(nTemp, sRain)
end