How to define a Variable in pricing scripts
This short documentation will show you how to define a variable once in a formula(script) and use it later by calling the variable name where-ever you need it, instead of applying the variable value on different lines of the script.
For that you would need to assign a suitable variable name to the value you are using in your script. To satisfy also the JavaScript naming conventions it is recommended to use camelCase for variable names. e.g. variable name “materialDensity” for the density of a specific material.
As the next step, there is a need to simply assign the desired value to the variable at the first few lines of the script, before the code lines which you want to apply that value.
within one line there is the possibility to define the variable and assign the desired value. as an example:
let materialDensity = 1.04;
Later on the next lines of the script, where you need to set the variable value, the variable name can be used instead, so instead of:
let totalMaterialPrice = (materialUsed*1.04*materialPrice + support.volume*supportPrice*supportDensity*supportInfill)*0.000001;
this can be replaced:
let totalMaterialPrice = (materialUsed*materialDensity*materialPrice + support.volume*supportPrice*supportDensity*supportInfill)*0.000001;