question

Bryan Suharik avatar image
1 Like"
Bryan Suharik asked Mischa Spelt edited

Write to Global Table not working?

Hi there, I am a bit confused.

I wrote my code to apply to an on entry trigger of a Queue ("GreenRow"). The code shows up in the treenode script, but the global table never updates when the model is ran.

However, when i manually click on the Queue and set the onentrytrigger to "Write to Global Table", the model runs fine and updates the global table correctly. I went back to the treenode and saw the new code from the manual entry, deleted it back to my original code and then my original code worked fine...

Is there some sort of APPLY command i need to enter when directly writing to the entrytrigger node?

treenode entrynode = node(">variables/entrytrigger",GreenRow); 

string entrycode = "\
treenode item = parnode(1);\
treenode current = ownerobject(c);\
int port = parval(2);\
string trackedvar = \"TrackedVariable1\";\
double initial = 0;\
double val = getentrytime(item);\
settablenum(\"GlobalTable27952\",1,1,453);\
if(getitemtype(item) == 1)\
settablenum(\"GlobalTable27952\",1,1,initial + val);"; 

setnodestr(entrynode, entrycode);

Thanks

I'd like to build a table timestamping every entry time for each item type. The columns would be the item types and the rows each time stamp.

FlexSim 16.0.6
global tablecodeentrytrigger
· 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.

Bryan Suharik avatar image Bryan Suharik commented ·

Correction... settablenum(\"GlobalTable27952\",1,1,initial + val);"

0 Likes 0 ·

1 Answer

Matt Long avatar image
5 Likes"
Matt Long answered Bryan Suharik commented

If you're trying to dynamically add code to an object's triggers, you need to let the object know that it has code that needs to be executed. This can be done by calling the following code on the node once you set the code:

switch_flexscript(triggerNode, 1);
buildnodeflexscript(triggerNode);

When you add code using the object's properties window, this is happening automatically for you. That's why it worked after you added code to the trigger and then replaced it with your new code.

If this is being done before reset is pressed, then you can omit the buildnodeflexscript() line as that is done on Reset.

· 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.

Bryan Suharik avatar image Bryan Suharik commented ·

Thanks Matt! That worked... i knew about the buildnodeflexscript, but i was missing the switch_flexscript. It's running well now! Thanks!

Bryan

0 Likes 0 ·