question

samuel.p avatar image
3 Likes"
samuel.p asked samuel.p commented

Dot Syntax replacement for settablenum/str

First of all I love the new dot syntax and arrays that you've added with the new parser. I do think that more documentation regarding both should have been added to the user manual before the official release though. I was using the old array types in a couple of my models. The error threw me for a bit of a loop after upgrading the model file.

Just had a quick question in regards to setting a table's cell value using the new dot syntax.

What I've come up with is:

int tempValue = 3;
Table outputTable = reftable("tableName");
outputTable.cell(row, col).value = tempValue;

This seems to work but I wanted to double check if this is correct. If so I was assuming that setting it up this way would work as well but it doesn't:

int tempValue = 3;
reftable("tableName").cell(row, col).value = tempValue;

I'm assuming that reftable is returning a treenode type and not the new Table type. This leads me to believe that there may be another way?

FlexSim 17.0.0
flexscripttabledot syntax17.0.0
· 2
5 |100000

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

Matthew Gillespie avatar image Matthew Gillespie ♦♦ commented ·

The reason this doesn't work

int tempValue = 3; 
reftable("tableName").cell(row, col).value = tempValue;

is because reftable returns a treenode and not a Table object. You need to cast the treenode as a Table object. One way is the way you demonstrated where you assign the result of reftable to a Table object.

int tempValue = 3; 
Table outputTable = reftable("tableName");
outputTable.cell(row, col).value = tempValue; 

The other way is to use the as method that casts one type into another type (although it throws errors if it can't do the cast).

int tempValue = 3; 
reftable("tableName").as(Table).cell(row, col).value = tempValue;

We should have a replacement for reftable in 17.1 that will return a Table object instead of a treenode.

However, the easiest way to do this is to use bracket notation as Regan suggests.

2 Likes 2 ·
samuel.p avatar image samuel.p Matthew Gillespie ♦♦ commented ·

Okay cool that was more of the answer I was looking for. I was not aware that the you could use the bracket notation though so that does help. Thanks! :)

1 Like 1 ·

1 Answer

·
Regan Blackett avatar image
6 Likes"
Regan Blackett answered samuel.p commented

You can use bracket notation with the tables, and basically treat them like arrays like this:

outputTable[row][column] = tempValue;

This approach is also pretty smart in that it assigns the right data type depending if tempValue is a number or a string.

· 1
5 |100000

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

samuel.p avatar image samuel.p commented ·

That is a lot cleaning than using .cell().value - thanks for your input!

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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