question

Axel Kohonen avatar image
2 Likes"
Axel Kohonen asked Axel Kohonen commented

Why do the tasks not give any error when some parameters are left out?

tasktype-sendmessage-doesnotgiveerror.fsm

Hi,

See the attached model where I have a processor that in the onEntry creates a task for the operator. In the task the operator sends a message to itself. If I give all the parameters to TASKTYPE_SENDMESSAGE it works fine, but if I forget to give all the parameters I can pass numbers nicely through the function and even treenodes (if I parse them as treenodes) if I wish, but if I pass a node with tonum(node) then the onMessage trigger cannot parse the numeric value correctly. However, no error message is given, but the code just does not work as it should.

Am I doing something wrong when I would like to have an error in this case or when I am passing the node as a number? Passing as a node does not work with tasktype_sendmessage, but parsing as variant in teh receiving end works in this case. Is this the way to go or what should be done?

Thank you!

Kind regards,

Axel

FlexSim 16.2.0
task sequencevarianttasktype_sendmessage
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

Phil BoBo avatar image
6 Likes"
Phil BoBo answered Axel Kohonen commented

inserttask() is handling the parameters differently depending on whether you passed a 0 as the last parameter or not. This isn't about whether parameters are left out or not; it is about whether the last parameter is 0 or not.

From the documentation of TASKTYPE_SENDMESSAGE:

"var4: This parameter tells whether the message sent is to be a delayed message. If 0, then the message is sent immediately. If -1, then the message is sent delayed in zero time. Otherwise, the message is sent in the specified number of seconds."

When you leave off the last parameter, it defaults to 0, which sends the message immediately using sendmessage() rather than senddelayedmessage().

For some reason which I can't remember, sendmessage() and nodefunction() were updated to take variants, but senddelayedmessage() and inserttask() were left as taking doubles.

The behavior of the first inserttask() call (which calls sendmessage() instead of senddelayedmessage()) is behaving the way we designed it to work when we switched to using variants in FlexSim 7.7.

When var4 is 0, if you change line 4 of your messagetrigger to treenode param1 = msgparam(1); then it successfully gets the reference to the processor that you passed, as your line 8 shows. This is how it should work.

msgparam() is returning a Variant that contains a treenode. Then you are casting that treenode Variant into a double, which turns it into 0. This is how it is designed to work so that it becomes apparent that you erroneously tried to store a treenode reference on a variable that holds a number. Previously, it would happily move on through the code trying to use a number that may or may not return a reference to the original treenode; it may even possibly be a different treenode if the original was destroyed and another was allocated in the same place in memory, which is quite common but inconsistent between runs. This also makes it so that objectexists() will correctly return false when you try to do a comparison on that double value.

To fix the issue for both cases (when the reference is passed as a treenode variant (sendmessage(); inserttask par4 == 0) and when the reference is passed as a number (senddelayedmessage(); inserttask par4 != 0)), you can put a tonode() call around your msgparam() call:

treenode param1 = tonode(msgparam(1));

I'll add a note to the dev list to look into this more to determine what we should do about this. With the variant update, we were trying to get away from needing to use the tonode() command.

· 3
5 |100000

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