question

Jouky D avatar image
0 Likes"
Jouky D asked Jouky D commented

How to trigger OnReset: Reset the table of a Global Table by FlexScript?

Hello everyone,

I need to create a table using FlexScript and this table has to reset some values to 0 on Reset.

How do I trigger an event On Reset when I create a global table?


Thank you!

FlexSim 23.1.2
global tableflexscripton reset
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

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Jouky D commented

A table you create through Tools.create() will have a "resettrigger" node in its variables. Write the needed code to that node as a string and switch the node to flexscript.

1710231518971.png

Object newTable = Tools.create("GlobalTable");
treenode resetTrigger = getvarnode(newTable, "resettrigger"); // Add code that resets the first column to 0 resetTrigger.value = "Table current = param(1);\ for(int row = 1; row <= current.numRows; row++) {\     current[row][1] = 0;\ }"; // Switch to flexscript switch_flexscript(resetTrigger, 1); buildnodeflexscript(resetTrigger);

1710231518971.png (5.1 KiB)
· 6
5 |100000

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

Jouky D avatar image Jouky D commented ·

It's good your suggestion, however, It would be here for the user:1710232356189.png
Is there a way to do it? If not, I will accept your answer.

0 Likes 0 ·
1710232356189.png (8.1 KiB)
Felix Möhlmann avatar image Felix Möhlmann Jouky D commented ·

You can add markup text to the code that will appear in the On Reset field.

1710240888576.png

1710240897079.png

And \" works for me. Can't say why it doesn't for you. Can you attach the model where you tried to use it?

resettrigger-by-code-fm.fsm

0 Likes 0 ·
Jouky D avatar image Jouky D Felix Möhlmann commented ·

Don't worry! I can't attach de model:(


However, does in your model show the trigger event On Reset on:

When I use your code, it does not change On Reset box (but it executes the code On Reset). Is there a way to do it? It could be useful if the user has to change that code.

Thank you!:D

0 Likes 0 ·
Show more comments
Jouky D avatar image Jouky D commented ·

And when I call current[row]['Column1'] it returns an error because I use ' ' instead of " ". How do you use " " inside a code written inside another " "? I tried to put \", ' " ', / "... I thought \" would work as other posts said that, but, when I apply the code, it returns:
1710233724515.png

0 Likes 0 ·
1710233724515.png (5.4 KiB)