I’ve created a weather forecast from the dark sky API showing temperature highs, lows, sun up, sun down and windspeed in meters per second.
I’d like to re-calculate this to the Beaufort scale of windspeed.
My question:
Would I use a dictionary for that to calculate a value between a and b equals windspeed x BF?
Or if-then statements? (Or even JavaScript?)
My first thought was just ‘if’ based conditionals as it isn’t a calculation, but a reference value range lookup. However, I then realised that because the Beaufort scale is totally numeric in terms of values and the scale itself is integer values … a dictionary could in fact be used with a repeat loop to make things that much simpler.
This first custom shortcut converts wind speed in m/s into a Beaufort scale rating.
This second custom shortcut asks for a windspeed in m/s, calls the first custom shortcut to carry out the conversion and then displays some information back.
I would guess that the behaviour is different exactly because it is the beta. That’s what’s changed after all.
Can you post a screenshot of how the shortcut looks in whatever version 13/13.1 you are using? I’m not on iOS13 just yet as I need the stability and reliability of iOS12 just now, so I don’t know how this shortcut has changed.
My best guess is it will be something to do with the way the upgrade process has handled the variables. I know iOS13 has fundamentally changed the way it is working with variables, to focus on identifying them within steps rather than requiring additional steps to pass them on. To my mind that seems the most likely place for a bug to have been introduced.
I adapted it very slightly, but the error was present in both yours and my versions, checked today.
f.e. I switched a calculation around but that had no effect on the error.
Don’t have it in front of me to test, but I think from memory you should be able to select a “Text” or “Number” block in its place and set it to the variable you want.
I’ve rebuilt a shortcut as a subroutine that works as a string of if-then statements, and that produces the desired result. So for now I’m okay. (And tired of dragging identical blocks in 12 times…)
I like @sylumer’s solution better, it’s more elegant, but as that does not work right now I’m happy with this one.
Did you try what @Kaitlin suggested? It seems logical that having a text/number step with the magic variable in it would be the equivalent of an in-situ get variable.
You’re pulling the value of just the variable Beaufort right?
If so, go though and add something to display the values of Beaufort, your speed, and the dictionary value it is checking against on each loop iteration. Then display the value of Beaufort at the very end of the shortcut.
Beaufort should be updated with the new index value when it is greater than the associated windspeed. i.e. it is only ever set equal to a single integer value at any time.
I can’t immediately see anything from the screenshots or what you should have applied that could indicate why Beaufort should contain what sounds more like a dictionary or concatenation of multiple results, rather than a single integer.