question

SudheerReddy avatar image
1 Like"
SudheerReddy asked Joerg Vogel commented

Events- OnMessage

As shown in below image there are lot of events like OnEndCollecting, OnEntry, OnExit etc. I am trying to find these events and the functionality in Manual but not able to find where it is located in the manual. Do we get any material or help file to read.

I would like to know what is the OnMessage event and how it triggers.

FlexSim 20.0.0
events
events.png (19.8 KiB)
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

·
Braydn T avatar image
3 Likes"
Braydn T answered Joerg Vogel commented

@Sudheer R

This information can be found in the user manual at docs.flexsim.com.

Here is some general information about events:

https://docs.flexsim.com/en/20.0/ModelLogic/EventsStatesTriggers/KeyConceptsEvents/

Here is some information about the onMessage trigger:

On Message

The on message event will fire the object's on message trigger. This event is fired when the object receives a message.

It has the following parameters:

Event Parameter Type Explanation
Sending Object Object The object that sent the message.
Message Param 1 Variant This is a parameter that was passed through the message and could be a number, string, treenode or array.
Message Param 2 Variant This is a parameter that was passed through the message and could be a number, string, treenode or array.
Message Param 3 Variant This is a parameter that was passed through the message and could be a number, string, treenode or array.
· 6
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 ·

You find the events in the object references, too. Her are some links to examples.

1 Like 1 ·
Joerg Vogel avatar image Joerg Vogel commented ·

The On Message event is created upon:

  • sendmessage command
  • senddelayedmessage command
  • message(..) method of the FlexScript Class Reference of the Object Class

as following Tasktypes inside an inserttask command or addtask method of FlexScript Class of the TaskSequence Class

  • sendmessage (deprecated)
  • message
  • break
  • callsubtask
0 Likes 0 ·
Braydn T avatar image Braydn T Joerg Vogel commented ·

@Sudheer R

Did this answer help you? If so, could you please accept it? If not, could you let us know what else we can do to help you? Thanks!

0 Likes 0 ·
Allyson avatar image Allyson commented ·

Hi,

I hope you can help me, I'm having some issues with label data type mismatches on an OnMessage-triggered source activity.

In my model I have a trigger which sends a message to a specific object (with important message parameters), and that recipient object is running an object code instance which has an OnMessage-triggered source activity. From there, a token is created when the message is received, and I want the message parameters to be assigned as labels on that token. Where I am running into issues is with the Label Matching/Assignment table. It seems that the message parameters have hard-coded variable types associated with them and will not pass a pointer parameter through to the token label.

It's hard to explain, so I'll walk you through what's happening with screenshots:

Here is the pop-up window for the item-triggered Send Message operation. As you can see, I have 2 message parameters that are in use. The first parameter is an int type and the second parameter is an object pointer (in this case the pointer is stored on a label).

send-message-popup-incorrect-parameter-type.pngPopup window for the item-triggered Send Message operation

The first issue I encountered was that I noticed my second parameter not being passed through correctly to the outbound message. The value I was seeing in my 'Local Variables' debug tab was 0.00000 instead of the object pointer. When I clicked 'Directly edit code for this trigger' the issue became clear:

send-message-popup-code-editor-incorrect-parameter.pngCode editor for the item-triggered Send Message operation with default code

In the code editor, the message parameters were being declared as doubles by default (instead of the default code using var or Variant or something more flexible). I corrected this manually as shown:

send-message-popup-code-editor-incorrect-parameter.pngCode editor for the item-triggered Send Message operation with updated code

Then, at this point I verified in the 'Local Variables' debug tab that my outgoing message parameters were all showing up correctly (they were).

The OnMessage-triggered source activity then created the token upon message receipt, and assigned the token labels as defined in the Label Matching/Assignment table:

job-token-incorrect-label-assignment-type.pngOnMessage-triggered source activity token label definition

That token then moved on to a custom code activity where I noticed in the 'Local Variables' debug tab that casting the 'MsgParam2' label as an Object resulted in a null value:

job-token-incorrect-label-assignment-type-local-va.pngCustom code activity and 'Local Variables' debug tab showing null value for the requestedDestination variable

I printed the actual 'MsgParam2' token label to the output console just to see what it contained, and it returned a value of 2381206995120. I have no idea what this numeric value signifies or how it got there, but my guess is that the Label Matching/Assignment table is casting the token labels as numeric values by default, just like the popup window for the item-triggered Send Message operation had done before I changed it manually.

The problem this time is that I have no idea where to find the source code editor to modify the token label assignment operation so that my object pointer parameter is actually passed through. I looked through the model tree but I have no idea where that source code "lives".

Did I identify the issue correctly, and if so, can you please recommend a way to get around it? Thanks in advance!

0 Likes 0 ·
Felix Möhlmann avatar image Felix Möhlmann Allyson commented ·
The trigger code assigns the message parameters as numbers because the command senddelayedmessage() can only use numeric values as parameters.

You have to set the delay time to -1 for the trigger to use the sendmessage() command instead which works with variant values.

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Allyson commented ·

@Allyson, I’m sorry but the three last images haven’t made it into your comment. You can identify it by the number of links below a comment, if an attachment is really available in a post. By the way, if you have a question, then ask a question in new thread.

I assume that you work with some templates in your model. Only FlexScript Class API method object.message is able to send parameters of datatype variant, which includes treenode datatype. Older but still in template used commands like sendmessage or senddelayedmessage can only transfer datatypes of string or number. Please check template source code and replace older commands by newer class method message.

if you want to cast a strange number value into a node or pointer reference you do this by command tonode.

even in activities you find an icon looking like a parchment roll. This opens a code editor. A custom code activity is by default a source code activity. By inserting it you can choose a template using some predefined function. You have then a template [headline override] and source code editor as icons available.

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.