question

Albert L avatar image
0 Likes"
Albert L asked Albert L commented

Adding trigger through FlexScript

I would like to add an OnEntry trigger to a Queue using FlexScript. After the trigger is created, I would then know how to add code to the trigger (finding the node, then adding the code as string)

My current approach is to access the Queue node then add a blank node. Is there a better way to approach this?

treenode queue_node = model.find("Queue1");

treenode triggernode = queue_node.find(">variables).add();

triggernode.name = "entrytrigger";

FlexSim 19.0.0
flexscript
· 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.

Joerg Vogel avatar image Joerg Vogel commented ·

If I guess your background is of an experienced programmer starting to develop models with the FlexSim program package. If this a true assumption, then I recommend you call FlexSim directly to go to an individual training course.

0 Likes 0 ·

1 Answer

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered Albert L commented

The node is already there. You just don’t see the node in the properties of objects. And if the node isn’t there, add a source code in the properties and print something to the output console. If you need the changed object as an library object, then add it as an user library object.

But why do you want to add dynamically source code to a model?

While the model runs you can only add really new code if you type the code in an input field or send the code external from a server! Any other code would be just a combination of already written code somewhere in the model tree.

The standard to choose different behavior in an event trigger is a

switch - case structure, and there is more:

  • You can call user commands
  • You can send messages
  • You can execute code at tree nodes
  • You can execute strings from labels
  • You can execute strings in table cells
· 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.

Albert L avatar image Albert L commented ·

Hi Jorg, thanks for your reply.

I think adding the object into the library with triggers added is a better approach. I could then edit the code by finding the node and setting the node.value = "//code string here"

I found the solution to my issue however. The steps to adding a trigger are as follows:

treenode queue_node = model.find("Queue1");
treenode queue_variables_node = queue_node.find(">variables");
treenode triggernode = queue_variables_node.subnodes.add();
triggernode.name = "entrytrigger";
string triggercode = "//code string here";
triggernode.value = triggercode;
enablecode(triggernode);
buildnodeflexscript(triggernode);
1 Like 1 ·