Example onMessage trigger to a user command and error

Example onMessage trigger to a user command and error

raul_vazquez
Not applicable
645 Views
4 Replies
Message 1 of 5

Example onMessage trigger to a user command and error

raul_vazquez
Not applicable

[ FlexSim 20.1.0 ]

Hello All,


Im trying to do a user command onMessage trigger but I cant find the proper parameters and the proper way to do it, looks like that dont work due once is reading the local variable is like the current is the model itself instead the specific object that im sending this(to Object).

Could you please send me a short example in order to understand better:

-Parameters

-Return Type

Please refer to the image that im triying to do and if you can let me know what is my mistake i really appreciate.


In the first image i show how im calling the "userCommand" and how i create the parameters

27446-onmessage1.png

second image show the variable the current like the "model" instead to the object that i need.

27452-onmessage2.png

third image show the error that is making the system console.


27461-onmessage3.png

thanks a lot for the support.


0 Likes
Accepted solutions (1)
646 Views
4 Replies
Replies (4)
Message 2 of 5

joerg_vogel_HsH
Mentor
Mentor

The classic trigger approach works for current, because the node of the trigger is in the attributes tree of the object to find. Your user command is not in the object tree, it is in tools tree. And you find in the function header that current is declared by a function with c. c is a reference to the node of this code. The ownerobject is the object which contains the attribute tree. This leads to the object in the model. If you need the reference of current like the object, where you put your user command in, you must parse this parameter into your function call directly as a parameter. And you evaluate this parsed parameter with param(num number of order).

I think a return type is ONE type only. If you want to return a structure, you put the data into a node structure in the tree and you return a treenode reference to this structure parent node. Maybe there is already the possibility to return a variant. Then you would be able to return an array, which contains your structure. But it is still only one value of one type and in this case it would be Variant.

My personal remark on this endeavor. It is ambiguous to try to implement a complete functionality from start. Smaller steps of success are my favorite style to to begin with an endeavor.

Message 3 of 5

raul_vazquez
Not applicable

Hi Jörg, thanks for the feedback, Im using the user command in order to manage the code for multiple objects in the same user command instead of editing each object's message trigger separately.

I understood the tree concept and I changed so i changed easily due is the same object referenced to itselft and now I can do my logic many thanks, but I still having a lot of doubts in how to create it properly for example I didnt change the "return type" and the logic work so maybe is not the correct way to do it , do you have any example that I can take a look? or maybe some literature that I can take to learn please?

27482-1587232995436.png

0 Likes
Message 4 of 5

joerg_vogel_HsH
Mentor
Mentor
Accepted solution

here is an example to parse several values of different datatypes into an array. Then I cast it directly into a Variant datatype to return only one value. The example transmitts the variables of the header declaration of the On Message trigger through a user command.

myMessageCommand.fsm

Message 5 of 5

raul_vazquez
Not applicable

Thanks a lot, is more clear....

0 Likes