question

Ruan H avatar image
0 Likes"
Ruan H asked Ben Wilson commented

Difference between gettablenum and Table() [] []

error.png

i assumed 1&2 have the same meaning, also 3&4.

but in flexsim v2019, 3&4 reported error, but 1&2 are perfectly ok. details showed in foto.

pls, anyone can help me understand the differences, if there are, thanks a lot.

1 int chess_type = gettablenum("ChessInfo" ,row,col);

2 int chess_type = Table("ChessInfo")[row][col]

3 string chess_name =gettablenum("Chess_type " ,chess_type ,2);

4 string chess_name = Table("Chess_type ")[Chess_type ][2]

tablesgettablenum
error.png (129.8 KiB)
· 1
5 |100000 characters needed characters left characters exceeded

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

"gettablenum/str" are deprecated but should still work. It seems to be 2 causing the error in the code for shape8, by returning 0 instead of a valid row number.

Are the "row" and "shape" labels on shape8 correct?

Could you post a screenshot of your tables? Or better yet, upload the model (or at least the relevant part of it)?

0 Likes 0 ·

1 Answer

· Write an Answer
Ben Wilson avatar image
1 Like"
Ben Wilson answered Ben Wilson commented

Hi @Ruan H ,

FlexSim version 19.0 supports all the styles of syntax you're using. Here is a model I just used to test (tableCheck.fsm):

1634058806430.pngYour errors must be occurring in some other aspect of your code. Check your syntax. Check your variable values. Use the debugger to step through your code if you need to.

Good luck!


1634058806430.png (39.1 KiB)
tablecheck.fsm (16.1 KiB)
· 4
5 |100000 characters needed characters left characters exceeded

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

tablecheck.fsmerror1013.pngi have uploaded screenshot of both senario by debugging, also attached model. just want to understand if I did something wrong, or its just system bug.


ok-syntax-1013.png

0 Likes 0 ·
ok-syntax-1013.png (49.1 KiB)
error1013.png (25.3 KiB)
tablecheck.fsm (17.4 KiB)

@Ruan H ,

Here are your problems, given the following code from your sample model:

int chess_type1 = gettablenum("tt",1,1);
print(chess_type1);
string chess_name1 =gettablestr("xx",chess_type1,1);
print(chess_name1);

int chess_type1 = Table("tt")[1][1];
print(chess_type1);
string chess_name1 = Table("xx")[chess_type1][1];
print(chess_name1);

You get compile errors on lines 6 and 8 because you can't re-declare chess_type1 and chess_name1. You can re-use the variables, but you can't re-declare them. Just take out the "int" and "string" words, respectively, from lines 6 and 8.

Next, when you successfully run the code you get problems. This is because on line 1, you're reading the value of 0 out of your "tt" table and saving it as chess_type1. Then you use chess_type1 as your row on line 3. But there is no 0 row in a global table. They start at row 1. So you're just trying to read data that doesn't exist.

0 Likes 0 ·
Ruan H avatar image Ruan H Ben Wilson ♦♦ ·

@Ben, thanks a lot for the detail explaination


what really confused me is that when chess_type=0, only command Table() [][] report invalid row num, but if I replace it with gettablenum/string, no error report. as you can see in below foto

1. Using gettablenum/string print out 0 when chess_type = 0

ok-syntax-1013.png


2. Using command Table() [][] report invalid row num

error1013.png

0 Likes 0 ·
ok-syntax-1013.png (49.1 KiB)
error1013.png (25.3 KiB)
Show more comments

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.