ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
#1
|
||||
|
||||
Using OnStateChange
Since 4.5 there is this nice option to use the OnStateChange trigger. We have used this now in a project but found some problems with it. What happens now is (at least this is our idea after working with it):
1 The OnStateChange is called 2 The calculation is done 3 The original to state is set. The problem is that if you want to change the state into a different one (e.g. change allocated_idle into waiting for transporter) you have to create a senddelayedmessage to change the state after the action 3. And that triggers the onstatechange again so you also have to use a flag to prevent it executing again. This is slow and cumbersome. And is even more problematic if multiple state changes happen at the same time (e.g. allocated_idle and then travel_empty) because then you want to change the allocated idle but before your message comes it is already the new status travel_empty that you don't want to change. So our idea (Ralf, DJ and mine) is to call the trigger at the end and the user should be able to have a return value that set the new state. That way one can prevent the extra delayedmessage and prevent to trigger the OnStateChange again. Is this a possible change for the next release? Last edited by Steven Hamoen; 09-24-2009 at 11:21 AM. |
The Following User Says Thank You to Steven Hamoen For This Useful Post: | ||
RalfGruber (09-24-2009) |
#2
|
||||
|
||||
The feature you need is already in version 4.5. Flexsim uses the return value of OnStateChange to decide what, if anything, to do. If you return 0 from OnStateChange, it goes on its merry way and changes the state. If you return > 0, it will change to the state that you return (if you return STATE_IDLE, it will change to the idle state instead of whatever it was originally going to change to). If you return -1, it will do nothing, leaving the object in its original state.
|
The Following 12 Users Say Thank You to Anthony Johnson For This Useful Post: | ||
Tom David (09-24-2009) |
#3
|
||||
|
||||
Anthony, thanks a lot for the answer. Unfortunately this has costed us at least 2 days programming and testing
May I repeat an earlier proposal and put this trigger in the basicFR, TE and conveyor for version 5.0. That way it can also be neatly described in the helpfile and I think that this is mainly used by library builders anyway. |
The Following 5 Users Say Thank You to Steven Hamoen For This Useful Post: | ||
Tom David (09-25-2009) |
#5
|
||||
|
||||
Anthony,
this one hasn't made it into the release yet. Are you planning to add the State Change Trigger to the BasicFR, BasicTE, and maybe BasicConveyor as suggested? Thanks Ralf FlexSim |
#6
|
||||
|
||||
Since Version 4.5 the method has changed a bit. Here is a summary:
You still have to build this trigger on your own under the node behaviour+eventfunctions. After highlighting the node eventfunctions insert a node into the eventfunctions by pressing the return button. By a clic on the plus sign next to the eventfunctions node the new node is shown in the tree. Rename the node to "OnStateChange". In the context menu right mouse button over the node choose Build>Toggle Node as FlexScript. The Node changes from a circle to a square and a red "S" is visible in it. Still you can't add any code to the node. Use again the context menu and choose Node> Add Text Data or highlight the node and press "t" on the keyboard. Now there is on the right side a text editor. The pointer current is here just "c". Code:
treenode current = c; After reseting the model the red S turns black. All this you can found in the forum at different places, too. /threads/thread1727 https://www.flexsim.com/community/fo...ead.php?t=1416 therein: https://www.flexsim.com/community/fo...0&postcount=12 Jörg |
#7
|
||||
|
||||
Joerg,
yes, I know how to do it as an experienced user. I just wanted to see, if the developers plan to make it accessible on the trigger's tab of the GUIs for BasicFR, BasicTE, and BasicConveyor for less experienced users...the reason is that I had a user currently asking for this functionality not knowing, it is already available...in the tree. Any feedback from the development team? Thanks Ralf FlexSim |
#8
|
||||
|
||||
I will put this on the BasicFR and BasicTE, but we have no plans of making improvements to the legacy conveyor objects.
|
The Following User Says Thank You to Anthony Johnson For This Useful Post: | ||
RalfGruber (03-10-2015) |