Check Variables for Let

As you may know we have a variable check for FileMaker script workspace for macOS in MBS FileMaker Plugin. This works fine for most scripts, but you may need to know a few pitfalls. Since the plugin reads what is in the script workspace window and FileMaker truncates long lines, it will not catch a variable mistyped in a very long line. When we read a calculation like this one:

Let([
	// define some variables
	$varDefined = 1; $secondVarDefined = 2]; $varDefined)

The plugin sees it as

Let([	// define some variables $varDefined = 1; $secondVarDefined = 2]; $varDefined) 

We don't get line breaks, so we have no idea where the comment ends and thus we can't find mistyped variable there.

There has been a problem that not scanning Let() for variable definitions, we now allow you to add a comment in front of the Let() or custom function call to define the variables: Start with a // comment and add they keywords @variable, @parameter or @constant (or shorter @var, @param or @const), then add a new line and continue with the calculation.

comment and add they keywords @variable, @parameter or @constant (or shorter @var, @param or @const), then add a new line and continue with the calculation.

e.g.

// @var $varDefined, $secondVarDefined
Let([
// define some variables
$varDefined = 1; $secondVarDefined = 2]; $varDefined) ] 
 
The plugin will recognize the comment and accept the variable even as we can't parse the Let statement due to missing line breaks.
 
Here is a test script showing various checking situations.
 
# you define a variable regularly
Set Variable [ $var1 ; Value: 1 ] 
# and use it
Set Variable [ $var2 ; Value: $var1 + 1 ] 
# now we define one via comment in Let()
Set Variable [ $test ; Value: 
	// @var $varDefined, $secondVarDefined
	Let([
	// define some variables
	$varDefined = 1; $secondVarDefined = 2]; $varDefined) ] 
# or here in a comment line to define a variable set by custom function:
# @var $thirdVarDefined
Set Variable [ $test ; Value: SomeCustomFunction ] 
# or now with comment inline:
Set Variable [ $test ; Value: 
	// @var $thirdVarDefined
	SomeCustomFunction ] 
# and use them
Set Variable [ $r ; Value: $varDefined + $secondVarDefined + $thirdVarDefined ] 
# If you don't declare it, we may catch it as an error:
Set Variable [ $test ; Value: Let([$NotDefined = 1]; 1) ] 
Set Variable [ $test ; Value: $testing + 1 ] 
# and this includes using an accent, which gives a different name:
Set Variable [ $test ; Value: $varDefĂ­ned + 1 ] 

Please try MBS FileMaker Plugin 13.5 pre-release to try this and let us know if you find a problem or just like this new feature.

3 Likes

Thanks @MonkeybreadSoftware for adding this feature.

Is it possible to have that variable notation be available for the rest of the script ( or within the scope of the number of lines set ), like script steps are?

1 Like

Please explain.
You can use normal comments to declare variable to MBS Plugin with @variable or others. New is to do this for comments before Let() to do the same for the variables in Let statement.

When I requested the feature, the thought was to be able to not use the comment script step in some areas. Some devs don’t like adding those script steps. So being able to place them in line with the calculation makes the script a little cleaner.

The script step is an ok option. But there are times we don’t want the added visual noise.