In the code edit fields you may find seemingly weird gray text strewn throughout the code. For example, you might find the following piece of code:
/**By Expression*/ /** /nExpression: */ double value = /**/10/**/; return value; /** /n/nNote: The expression may be a constant value or the result of a command (getitemtype(), getlabel(), etc).*/
The gray text is called template code. Template code is used in picklist popups as talked about in the Picklists page. When the button is pressed, FlexSim parses the template code and displays parameters in the correct places within the popup.
/***popup:ValuesByCase:hasitem=1:valuestr=Port:doreturn=1*/
This template code is an instruction to open a popup.
int case_val = /***tag:ValueFunc*//**/getitemtype(item)/**/;
When the popup opens, it parses the script for instances of /***tag:TagName*//**/Value/**/ and places Value in the appropriate field in the popup. When the popup closes, the values in each field take the place of their respective Value. In this way, the /***tag: mechanism creates a two-way link between the script and the popup.
Here's a screenshot from from Using Global Lookup Table from the Inter-Arrivaltime drop-down menu in the Properties window of a Source object:
Template Text Popups
If no popup exists for the template code, or if a user creates custom template code, FlexSim will display a template text popup. The above popup is editing the same values as the Popup displayed above. Template Text consists of black and blue text. Blue text is editable text, just like you would edit in an edit field of a normal popup. In your code, to specify a section of fixed black text, use a multi-line comment but add an additional asterisk to the start tag: /** . By adding this extra asterisk, it signals to FlexSim's template code interpreter that this is a section of fixed black text that should show up when the user looks at the template text. In the example at the top of this section, the text: /**By Expression*/ makes it so the text "By Expression" will show up in black text in the template drop-down.
To specify the blue editable text, you want the input from the user to be part of the actual code. So to start blue text, you go into a multi-line comment then immediately go out of the comment: /**/ . You use the same tag to get out of a section of blue text. Thus, in the code above, the value 10 is made available for changing when the template text is shown:
double value = /**/10/**/;
Because these are comments, the FlexScript parser only sees: double value = 10; but the advantage is that now you (or another modeller) can quickly change the 10 value to something else just by pressing the button and editing the blue template text.
You may also notice that the comments will occasionally include a /n tag. This tag specifies a new line to be made in the fixed black template text. You can also specify a new line just by putting a new line in the comment, but often you will want your template code to take up as little space as possible so that the code itself can be viewed more easily.
Comments
In FlexScript, you can "comment out" a section of text so that the FlexScript parser does not look at that text as part of the code. This allows you to add descriptive text that explains what the code does. There are two ways to make comments. The first is the one-line comment, and is done with two forward slashes: //. The example below shows a one-line comment
// This is my one-line comment, it ends at the end of this line
A one-line comment extends to the end of that line of text. The other comment is a multi-line comment. Here you signal the start of the comment with the text: /* and signal the end of the multi-line command with the text: */ as shown below:
/* this is my multi-line comment it can span as many lines as I want it to */