Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Nested "Let" inside "Case", which is the result of another "Let"?

Featured Replies

I just edited this to make sense (I hope).

 

Basically my objective is to reduce the number of global variables in a script when their conditions are overlapping. For instance, where the comment is in the below Let statement, can I add: $$Command2 = "Yield" given the same conditions?  Again, I know that I can just create another global variable but I'm trying to keep it simple given the number of lines in the actual code. Thanks in advance!

 

$$Command1 =

 

Let([

 

~A = Case(

                 conditions 1, 2, 3; "Black";

                 conditions 3, 4, 5; "White"

                 )

 

];

 

Case(

         ~A = "Black";  "Stop"; //<--can a Let statement be added to create additional variables?

         ~A = "White"; "Go" 

 

)

Is there a reason you are using global variables in a script? Global variables need (should) only be used if the value needs to persist after the script has run.

 

If the value does not need to persist then do not use global variables. Use single-$ variables instead.

 

A good use of a global variable might be to remember whether a script has run in the current session. The script would check whether a global variable $$has_run=1. If it does it would exit the script, if not it would run the script steps then set the variable to 1 and exit.

  • Author

The reason I use globals is because they survive from one companion script to next. Basically, I set up a separate script with a bunch of interdependent variables to reduce the leg work in separate primary scripts. What's the downside to using globals?

"~A = "Black";  "Stop"; //<--can a Let statement be added to create additional variables?"

 

Yes, you could do that in two ways:

 

~A = "Black"; "Stop" & Let ( $$Command2 = "Yield" ; "" )

or

~A = "Black";  Let ( $$Command2 = "Yield" ; "Stop" )

  • Author

Thanks, Raybaudi. But now I'm wondering if there is in fact a downside to using global variables aside from cluttering the data viewer?

After you've forgotten what a global variable is for, it's difficult to track down all calculations that reference it, which sets up a disincentive to editing it's value or choosing not to set it in the future or refactoring in general for fear of breaking something. Global state leads to more tightly coupled code that is difficult to maintain with confidence.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.