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.

Axel Kohonen avatar image Axel Kohonen commented ·

Hi @phil.bobo

Thank you for the answer and putting a note on the dev list! It would be great if inserttask would give an error when not giving all the required parameters for a certain task type.

This issue obviously arises from a wrong way to use TASKTYPE_SENDMESSAGE but is it not so that if you want to pass the variables onwards then you could parse them as variants in the onMessage trigger and then pass these variants into a user command and it should always work regardless if the last parameter was given?

Thanks!

Axel

0 Likes 0 ·
Phil BoBo avatar image Phil BoBo ♦♦ Axel Kohonen commented ·

Again, the amount of parameters given is irrelevant. Any optional parameters that are not passed to a function are given default values. The default value for parameter 4 is 0, which means use sendmessage() instead of senddelayedmessage() when you execute the task.

You can give it all the parameters, and if the last parameter is 0, it will behave the same way as if you hadn't passed a last parameter at all. This issue has nothing to do with how many parameters you passed.

You gave it all the required parameters. The last 4 parameters are optional.

This issue has nothing to do with a "wrong way to use TASKTYPE_SENDMESSAGE." It has entirely to do with the fact that sendmessage() takes variants and senddelayedmessage() takes numbers, as I explained in my original post.

2 Likes 2 ·
Axel Kohonen avatar image Axel Kohonen Phil BoBo ♦♦ commented ·

Hi Phil,

Ah, now I get it. Thank you!

Axel

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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