OnStateChange node under behaviour/eventfunctions as flexscript

OnStateChange node under behaviour/eventfunctions as flexscript

patrick_zweekhorst
Advocate Advocate
315 Views
15 Replies
Message 1 of 16

OnStateChange node under behaviour/eventfunctions as flexscript

patrick_zweekhorst
Advocate
Advocate

[ Flexsim 17.1.6 ]

Hi All,

I have a module where I have added an OnStateChange dll function to an object in the library. This function worked good and did what I wanted, until I used a wait for event in processFlow where I am waiting for the OnStateChange on the same object. It looks like the wait for event in the processFlow creates a flexscript node in the behaviour node of the object in the model:

9009-onstatechange.png

I think this causes that the dll function in the library is no longer called ( below the dll function in the library )

9010-onstatechange2.png

How can I fix this? Manually copying the dll node from the library over the flexscript node in the model works, but that then needs to be done for each object in the model.

Thank you for any help,

Patrick

0 Likes
Accepted solutions (1)
316 Views
15 Replies
Replies (15)
Message 2 of 16

philboboADSK
Autodesk
Autodesk
Accepted solution

Try binding your OnStateChange node within your object's bindEvents() cppfunction:

bindEventByName("OnStateChange", node_b_OnStateChange, "OnStateChange");


Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 3 of 16

patrick_zweekhorst
Advocate
Advocate

Hi @phil.bobo ,

Thanks for your solution. Is it correct that I no longer need to have the OnStateChange dll node under behaviour/eventfunctions? This node should now be under variables as I understand correctly? It does work if I do that.

0 Likes
Message 4 of 16

philboboADSK
Autodesk
Autodesk

"Is it correct that I no longer need to have the OnStateChange dll node under behaviour/eventfunctions?"

I don't know what your object is or what you were using the OnStateChange attribute for. So I can't definitively answer this question.

"This node should now be under variables as I understand correctly?"

The location of attribute nodes is irrelevant. You can put them anywhere in the object's attribute tree and the object can find them.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 5 of 16

patrick_zweekhorst
Advocate
Advocate

Hi @phil.bobo

The object is a custom crane, which has a custom state profile. I however do want to use the states set by FlexSim. I had therefore added the OnStateChange event to the eventfunctions. This did not work completely in combination with the wait for event in processFlow.

After I added the bindEventByName in the cppfunction I got an OnStateChange node under the variables in the custom crane when I drag it in the model. This looks to be working fine and I therefore removed the OnStateChange node from under the eventfunctions node in the library and added that node under variables in the library object. I thought that otherwise I would have a OnStateChange node under eventfunctions and under variables, and that does not look efficient.

0 Likes
Message 6 of 16

philboboADSK
Autodesk
Autodesk

That's behaving differently than I thought it was.

It may be working correctly now, but you may run into issues if something changes in a future version.

In your case, I would copy the BasicFR's implementation:

1. A statechange variable that is connected to your DLL with your custom state profile code.

2. An OnStateChange attribute under behavior/eventfunctions.

3. An _OnStateChange under behavior/eventfunctions/eventInfo to specify parameters

4. An onStateChange() cppfunction called from the OnStateChange attribute that calls the statechange variable.

5. A bindEvents() cpp function that calls

bindEventByName("statechange", node_v_statechange, "OnStateChange", EVENT_TYPE_DEFAULT);

If you follow the BasicFR's example, your object is more likely to continue to function correctly in future releases.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 7 of 16

philboboADSK
Autodesk
Autodesk

Also, if you are just using the OnStateChange to handle a custom state profile, then you don't actually need an OnStateChange attribute. Follow the MultiProcessor's example and use two state profiles: the default state profile that uses the states set by FlexSim, and an extra state_profiles state profile where you keep track of your own states, passing 1 as the profile number when you want to change the states in your custom state profile.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 8 of 16

patrick_zweekhorst
Advocate
Advocate

Thanks @phil.bobo ,

I will try this and come back to you if I have any other questions or remarks

0 Likes
Message 9 of 16

patrick_zweekhorst
Advocate
Advocate

Hi @phil.bobo

It is not completely working jet. I have tried to follow your steps and looked at the BasicFR. This is how the tree looks now:

9029-onstatechangetree.png

Where the StateChange node is under variables. In the bindEvents function I have added the code you said:

bindEventByName("StateChange", node_v_statechange, "OnStateChange", EVENT_TYPE_DEFAULT );

The problem now is that the OnStateChange function does not fire. What am I missing?

Thank you for the help.

0 Likes
Message 10 of 16

philboboADSK
Autodesk
Autodesk

Try renaming the eventInfo node to _OnStateChange like the BasicFR is.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 11 of 16

patrick_zweekhorst
Advocate
Advocate

Hi @phil.bobo,

I changed the name of the eventinfo node to _OnStateChange. This is how it is in 17.2 for the BasicFR, but not for the BasicFR in 17.1 ( where I am in with this module) . This however did not make ant difference. The StateChange dll node is still not called.

Do you have any other ideas on what could be going wrong? I am not completely sure if it is relevent, but the dll node still has the color red.

Thank you,

Patrick

0 Likes
Message 12 of 16

philboboADSK
Autodesk
Autodesk

The DLL node remains red until something calls it, then it connects and turns black.

Try defining your onStateChange() cppfunction in your module dll instead of in the tree.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 13 of 16

patrick_zweekhorst
Advocate
Advocate

Hi @phil.bobo

How would I define the onStateChange in the module dll? The onStateChange function of the BasicTE is not virtual, so I can not override that function in cpp.

Thanks for your help.

0 Likes
Message 14 of 16

philboboADSK
Autodesk
Autodesk

o(TALUMIS_CRANES::TalumisCrane,c) is getting a TalumisCrane* reference.

Can you not just add a method to your TalumisCrane class and call it?

If you get a syntax error trying to call it from a C++ node in the tree, toggle your OnStateChange attribute as DLL and put that code into your DLL. Then call it from the DLL.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 15 of 16

patrick_zweekhorst
Advocate
Advocate

Hi @phil.bobo

Do you mean that I would need to change the name of my function? Instead of OnStateChange choose another name?

Or do you mean that I would need to make a free function in cpp?

I can toggle the OnStateChange attribute as dll and call a function in the dll. That is more or less what I started with. That would mean that there is nothing under cppfunctions for the TalumisCrane

0 Likes
Message 16 of 16

philboboADSK
Autodesk
Autodesk

cppfunctions is how you add methods to a class defined in the library tree. If you are using a module, your class is defined in your module. Just add a method to it. Yes, that means there is nothing under cppfunctions for the TalumisCrane.

You don't need to rename the OnStateChange attribute. Just change it from being toggled as C++ to being toggled as DLL, and call the method on your class from that function in your DLL.



Phil BoBo
Sr. Manager, Software Development
0 Likes