Adding trigger through FlexScript

Adding trigger through FlexScript

albert_l
Not applicable
745 Views
3 Replies
Message 1 of 4

Adding trigger through FlexScript

albert_l
Not applicable

[ FlexSim 19.0.0 ]

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";

0 Likes
Accepted solutions (1)
746 Views
3 Replies
Replies (3)
Message 2 of 4

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

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
0 Likes
Message 3 of 4

joerg_vogel_HsH
Mentor
Mentor

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
Message 4 of 4

albert_l
Not applicable

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);