question

Kari Payton avatar image
1 Like"
Kari Payton asked Logan Gold commented

Global table lookup error

On a delay, in the old version, whenever I set it to time: global table lookup, there was an option for what type of data (number, expression, automatic). In the new version, whenever I create a delay time or create a label: global table lookup, it doesn't read a value from the table. The values in the table are set as strings with a triangular distribution. numberofcranesneeded-tur-rev-16.fsm

FlexSim 17.1.0
global table
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Logan Gold avatar image
3 Likes"
Logan Gold answered Logan Gold commented

I'm about to describe a change between older versions of FlexSim and FlexSim 2017. The simple answer is bolded down below if you don't care about all the extra stuff.

With older versions of FlexSim, the only data types that a global table could hold were either numbers or strings. So in the "Global Table Lookup" picklist option, if you chose "Number", the underlying code would assume the value in the table cell being looked up is a number and use the gettablenum() command to retrieve that value from the cell. If you chose "Expression", the underlying code would assume the value is a string and would use the executetablecell() command to execute that string as FlexScript and return whatever the FlexScript evaluates to. The "Automatic" option would try to determine the data type of the table cell first, then do one of those two options.

With the new dot syntax stuff, global tables can now hold 7 different types (all of which are named in the Global Tables section of the User Manual). One of those types is FlexScript.

Also, when using the Global Table Lookup option in a Delay activity, the code no longer calls the same commands as described above. Instead, the code creates a variable that is a Table class and uses it to reference the specified global table. That variable can then access cells in the global table by using bracket operators, like this (this is not the same code found in Global Table Lookup):

Table table = Table("Fred"); // Get a reference to a global table named Fred
return table[1][1]; // Return the value from the table cell found at row 1 and column 1

So when a value is returned from the global table, whatever is returned depends on what data type that specified table cell was set to. When a cell is using the FlexScript data type, it will execute the value of the cell as FlexScript and return whatever the FlexScript returns.

All of your old Delay activities will still work after upgrading the model to FlexSim 2017. However, if you add any more Delay activities and use the Global Table Lookup option in your upgraded model, I would suggest changing the data type of the appropriate cells in your global table to the FlexScript data type by right-clicking on individual cells, rows, or columns, like this:

Otherwise, any new Delay activities will treat the values in those cells as strings and the delay time will probably end up being 0. Making this change will not affect your old Delay activities, as the executetablecell() command will still return the right data even if the cells are set to the FlexScript data type.


· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

jing.c avatar image jing.c commented ·

Hi, Logan.

Data type of the appropriate cells can be changed to FlexScript data type is only worked in 2017.1 not all the 2017.

3 Likes 3 ·
Talia Z avatar image Talia Z commented ·

@Logan Gold Hi Logan! Would you mind sharing how to repeat this code in version 18? I believe the second line of this code produces an error in the updated version.

Table table = Table("Fred"); 
return table[1][1];
0 Likes 0 ·
Logan Gold avatar image Logan Gold ♦♦ Talia Z commented ·

@Talia Z,

It should be the same code in FlexSim 2018. For an error to occur, there is probably an issue with the table name or the value in the table.

For example, in the example code, you will need to make sure there is a table that has already been created called Fred, or change the name between the quotation marks in the code to the name of another table in your model that has already been created. Then, make sure the table has at least one row and one column.

You might also have an issue with the value of row 1, column 1 that could be causing the error. If that cell is set to be FlexScript, and the FlexScript is incorrect, it might throw an exception that has nothing to do with the Table code.

If this doesn't help you resolve your issue, please post a new post on Answers and include the error that you are receiving. If you could also post a model that shows the issue, or describe a way to replicate the issue in FlexSim, that will help us find a solution quickly.

1 Like 1 ·