Nested if issues, suggestions welcome!

I have this code (to convert windspeed to Beaufort).

$(round(#WND#))>72?12:$$(round(#WND#))>62?11:$$(round(#WND#))>53?10:$$(round(#WND#))>45?9:$$(round(#WND#))>37?8:$$(round(#WND#))>29?7:$$(round(#WND#))>23?6:$$(round(#WND#))>16?5:$$(round(#WND#))>11?4:$$(round(#WND#))>6?3:$$(round(#WND#))>2?2:$$(round(#WND#))>0?1:0$ bft

In preview mode on facer.io it works fine. But on my watch it shows now ‘54321 bft’ in stead of ‘5 bft’.

Any ideas?

I just placed your code into the Text Box of a text element. At first it came back 54321… so I widened the text area and resynced it and it seems to work fine. I have a 7 mph wind locally and the code is saying it’s 1 bft. This is using a cheap TicWatch C2 as a test watch. Usually if something doesn’t work it won’t work on that watch. (sometimes perfectly good code won’t work on it either) I’ve now synced it to my Galaxy Active 2 and it’s telling me it’s 3 bft for the same 7 mph breeze. You might have to alter your coding into a slightly different form. something like

$(round(#WND#))>72?12:$$(round(#WND#))>62&&(round(#WND#))<73?11:$…

Nested expressions can be very picky sometimes.

Thanks, @mrantisocialguy.
I gave that a try:
$(round(#WND#))>72?12:$$(round(#WND#))>62&&(round(#WND#))<73?11:$$(round(#WND#))>53&&(round(#WND#))<63?10:$$(round(#WND#))>45&&(round(#WND#))<54?9:$$(round(#WND#))>37&&(round(#WND#))<46?8:$$(round(#WND#))>29&&(round(#WND#))<38?7:$$(round(#WND#))>23&&(round(#WND#))<30?6:$$(round(#WND#))>16&&(round(#WND#))<24?5:$$(round(#WND#))>11&&(round(#WND#))<17?4:$$(round(#WND#))>6&&(round(#WND#))<12?3:$$(round(#WND#))>2&&(round(#WND#))<7?2:$$(round(#WND#))>0&&(round(#WND#))<3?1:0$ bft

I’t s now like this, but now it shows 40 bft, the max is 12…

I just tried it also and it shows 20 on my TicWatch. Hopefully someone who is a master at Facer math expressions will see your post and be able to help. My only other thought would be to separate each expression into text elements and use it in the Opacity box with the “Beaufort Speed” in the Text Box.

So then I thought: “maybe it’s the zero”, so I changed to:

$(round(#WND#))>72?12:$$(round(#WND#))>62&&(round(#WND#))<73?11:$$(round(#WND#))>53&&(round(#WND#))<63?10:$$(round(#WND#))>45&&(round(#WND#))<54?9:$$(round(#WND#))>37&&(round(#WND#))<46?8:$$(round(#WND#))>29&&(round(#WND#))<38?7:$$(round(#WND#))>23&&(round(#WND#))<30?6:$$(round(#WND#))>16&&(round(#WND#))<24?5:$$(round(#WND#))>11&&(round(#WND#))<17?4:$$(round(#WND#))>6&&(round(#WND#))<12?3:$$(round(#WND#))>2&&(round(#WND#))<7?2:$$(round(#WND#))>0&&(round(#WND#))<3?1:$$(round(#WND#))=0?0$ bft

Now it shows: “4$16=0?0$ bft” on my watch…

I separated it into 13 text elements using $#WND#>0&&#WND#<=2?100:0$ in the opacity box for 1 bft and $#WND#>2&&#WND#<=6?100:0$ for 2 bft, and so on. It “seems” to be working with both watches giving the same bft readout.

This is what I used if you’re interested in trying it.

12 BFT $#WND#>72?100:0$
11 BFT $#WND#>62&&#WND#<=72?100:0$
10 BFT $#WND#>53&&#WND#<=62?100:0$
9 BFT $#WND#>45&&#WND#<=53?100:0$
8 BFT $#WND#>37&&#WND#<=45?100:0$
7 BFT $#WND#>29&&#WND#<=37?100:0$
6 BFT $#WND#>23&&#WND#<=29?100:0$
5 BFT $#WND#>16&&#WND#<=23?100:0$
4 BFT $#WND#>11&&#WND#<=16?100:0$
3 BFT $#WND#>6&&#WND#<=11?100:0$
2 BFT $#WND#>2&&#WND#<=6?100:0$
1 BFT $#WND#>0&&#WND#<=2?100:0$
0 BFT $#WND#==0?100:0$

It’s a pain to do so many text elements but it does bypass the nested conditional issue.

The issues with nested conditionals is my top Facer bug and has been there since I started using Facer more than a year ago.
Conditionals is basic functionality in any programming language… Really hope @Facer_Official can fix this.

For now splitting into multiple layers is the only reliable way. :worried:

Thanks a lot, @mrantisocialguy and @mountain_lion for looking into this.
It’s indeed very, very silly that nested conditionals are such a pain in the… @Facer_Official !!!
Splitting into 13 layers is really stupid…
Perhaps I’ll spend time to do that later.

Hey @ma.polinder ,
I was looking at your problem and this seemed to work for me on my tic watch pro.
I used an && to encapsulate the output condition. $(#WND#)<=72**&&**(#WND#)>62?11:

Here is the entire statement.

$(#WND#)>72?12:$$(#WND#)<=72&&(#WND#)>62?11:$$(#WND#)<=62&&(#WND#)>53?10:$$(#WND#)<=53&&(#WND#)>45?9:$$(#WND#)<=45&&(#WND#)>37?8:$$(#WND#)<=37&&(#WND#)>29?7:$$(#WND#)<=29&&(#WND#)>23?6:$$(#WND#)<=23&&(#WND#)>16?5:$$(#WND#)<=16&&(#WND#)>11?4:$$(#WND#)<=11&&(#WND#)>6?3:$$(#WND#)<=6&&(#WND#)>2?2:$$(#WND#)<=2&&(#WND#)>0?1:$ bft

This is very similar to the logic @mrantisocialguy is using.

Good luck! :wink:

It worked, @rmcewen63!!!
Thank you so much!!!

1 Like