It is currently April 25th, 2024, 11:21 am

Conditionals in formulas

Get help with creating, editing & fixing problems with skins
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Conditionals in formulas

Post by jsmorley »

Ok, I'm stuck...

I use this calc, that uses the temperature from Yahoo Weather returned in a WebParser measure : [MeasureNowWeatherTemp]

[MeasureTempDesc]
Measure=Calc
Formula=MeasureNowWeatherTemp <= 30 ? 1 : ((MeasureNowWeatherTemp > 30) && (MeasureNowWeatherTemp < 50)) ? 2 : ((MeasureNowWeatherTemp >= 50) && (MeasureNowWeatherTemp < 80)) ? 3 : ((MeasureNowWeatherTemp >= 80) && (MeasureNowWeatherTemp < 89)) ? 4 : (MeasureNowWeatherTemp >= 90 ? 5 : 6)
Substitute=".0":"","1":"f**king cold","2":"sorta chilly","3":"fairly warm","4":"sorta hot","5":"f**king hot"

Later on, I use this in a call to JSMSpeak.exe to have it "speak" the time and weather on the hour. (with some rude commentary, I changed to ** for purposes of the forums.)

[MeasureSpeak]
Measure=CALC
Formula=(MeasureNewHour=0 && MeasureFirstRun=1)
IfEqualAction=!Execute ["#ADDONSPATH#JSMSpeak\JSMSpeak2.exe" "[MeasurePartOfDay]. It is [MeasureSpeakTime], and the weather is [MeasureNowWeatherConditions] and [MeasureTempDesc] at [MeasureNowWeatherTemp] degrees." "#Language#"]
IfEqualValue=1
DynamicVariables=1

All works ok, EXCEPT that [MeasureTempDesc] always returns either 4 or 5 which is then appropriately substituted. If the temp is anything below 90, it is "sorta hot". If above 90, it is well, that last one.. ;-)

I suspect I have some anomaly in how I have the conditionals laid out, probably how I am using parens, but I don't see it right off. Anyone spot the issue?
User avatar
limpet
Posts: 34
Joined: April 21st, 2009, 5:25 pm
Location: NC, USA

Re: Conditionals in formulas

Post by limpet »

You're not putting enough parenthesis in.

Code: Select all

[MeasureTempDesc]
Measure=Calc
Formula=MeasureNowWeatherTemp <= 30 ? 1 : (((MeasureNowWeatherTemp > 30) && (MeasureNowWeatherTemp < 50)) ? 2 : (((MeasureNowWeatherTemp >= 50) && (MeasureNowWeatherTemp < 80)) ? 3 : (((MeasureNowWeatherTemp >= 80) && (MeasureNowWeatherTemp < 89)) ? 4 : ((MeasureNowWeatherTemp >= 90 ? 5 : 6)))))
Substitute=".0":"","1":"f**king cold","2":"sorta chilly","3":"fairly warm","4":"sorta hot","5":"f**king hot"
I can't remember why but every time you nest another conditional, you have to wrap that whole part in parens.
Limpet makes music: [Soundcloud][Reverbnation][Myspace (ick)][Uvumi][Electronic/Dance]
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Conditionals in formulas

Post by jsmorley »

Ah, ok. I'll give that a go. Thanks.
User avatar
limpet
Posts: 34
Joined: April 21st, 2009, 5:25 pm
Location: NC, USA

Re: Conditionals in formulas

Post by limpet »

Actually, a better way to phrase that would be "every time you nest another conditional, you have to wrap everything after in a new set of parens."

That explains all the ))))) at the end of the line.
Limpet makes music: [Soundcloud][Reverbnation][Myspace (ick)][Uvumi][Electronic/Dance]
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Conditionals in formulas

Post by jsmorley »

Yep.. Got it now. Thanks much.

[MeasureTempDesc]
Measure=Calc
Formula=MeasureNowWeatherTemp <= 30 ? 1 : (((MeasureNowWeatherTemp > 30) && (MeasureNowWeatherTemp < 50)) ? 2 : (((MeasureNowWeatherTemp >= 50) && (MeasureNowWeatherTemp < 60)) ? 3 : (((MeasureNowWeatherTemp >= 60) && (MeasureNowWeatherTemp < 80)) ? 4 : (((MeasureNowWeatherTemp >= 80) && (MeasureNowWeatherTemp < 90)) ? 5 : ((MeasureNowWeatherTemp >= 90 ? 6 : 7))))))
Substitute=".0":"","1":"f**king cold","2":"sorta chilly","3":"fairly cool","4":"fairly warm","5":"sorta hot","6":"f**king hot"

Works good. I like having the google girl curse when it gets hot. ;-)

Next to add humidity and wind speed... "and the humidity is giving me a bad hair day and the wind is blowing my skirt up" :-)
User avatar
limpet
Posts: 34
Joined: April 21st, 2009, 5:25 pm
Location: NC, USA

Re: Conditionals in formulas

Post by limpet »

Haha, very clever.
Limpet makes music: [Soundcloud][Reverbnation][Myspace (ick)][Uvumi][Electronic/Dance]
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Conditionals in formulas

Post by jsmorley »

User avatar
limpet
Posts: 34
Joined: April 21st, 2009, 5:25 pm
Location: NC, USA

Re: Conditionals in formulas

Post by limpet »

Nice, you have your computer bid you a "good afternoon".
Limpet makes music: [Soundcloud][Reverbnation][Myspace (ick)][Uvumi][Electronic/Dance]