Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

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


This topic is 4372 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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" 

 

)

Posted

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.

  • Like 1
Posted

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?

Posted

"~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" )

  • Like 1
Posted

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

Posted

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.

This topic is 4372 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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