question

Raul Vazquez avatar image
0 Likes"
Raul Vazquez asked Raul Vazquez commented

Example onMessage trigger to a user command and error

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

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

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


thanks a lot for the support.


FlexSim 20.1.0
flexsim 20.1.0
onmessage1.png (62.1 KiB)
onmessage2.png (98.6 KiB)
onmessage3.png (26.1 KiB)
· 2
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 ·

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.

1 Like 1 ·
Raul Vazquez avatar image Raul Vazquez commented ·

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?

0 Likes 0 ·
1587232995436.png (237.5 KiB)

1 Answer

Joerg Vogel avatar image
1 Like"
Joerg Vogel answered Raul Vazquez commented

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


· 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.

Raul Vazquez avatar image Raul Vazquez commented ·

Thanks a lot, is more clear....

0 Likes 0 ·