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
|
|||
|
|||
Frame Animation based on Time
HI,
How do I make a basic custom load animation based on time using frames? I can change a frame once on some trigger, but I want a series of frames to change over say every quarter of a second to create a simple motion for an action such as Load. I can change frames based on position: http://www.flexsim.com/community/for...ghlight=frames But thats not what I want. I have a 1) BasicTE, and custom image frames to cycle through during load, or even offset triggers. 2) loading from a queue 3) pivoting to unload at a source I dont want to use crane or robot arm standard libraries. Currently, I can send a message in BeginOffset from BasicTE to itself, then OnMessage Code:
/**Custom Code*/ treenode current = ownerobject(c); double loadtime = getlabelnum(current,"loadtime"); double starttime = time(); int state = msgparam(1); double i = starttime; while( i <= (starttime + loadtime) ) { if (i >= (starttime + loadtime)) // End Frame setframe(current,5); else if (i >= (starttime + (3.0 * loadtime / 4.0))) // 3/4 time Frame setframe(current,4); else if (i >= (starttime + (loadtime / 2.0))) // 1/2 time Frame setframe(current,3); else if (i >= (starttime + (loadtime / 4.0))) // 1/4 time Frame setframe(current,2); i = time(); } Is there an example/thread on how to do this? |
#2
|
||||
|
||||
Just a few hints...
- "i" is a command in flexsim. You can overload a command with a new command (like your i) but it could be a source of failure. - "else if" isn't a command in c++ or flexsim. Your code looks normally like this: Code:
if(...) { ... } else { if(...) { ... } else { if(...) { ... } else { if(...) { ... } } } } Maybe this is a little help Last edited by Carsten Seehafer; 04-03-2009 at 04:46 AM. Reason: add warp <code> |
#3
|
|||
|
|||
Frame Animation based on Time
Hi Shanon,
I see why your code crashes Flexsim. The code which you are executing takes place at one instance in time. So i will always be smaller than (starttime + loadtime) and you get caught in a neverending loop. I think you can simply solve this problem by using delayed messages for each phase of the loading proces. So , senddelayedmessage(current, 1/4 * loadtime, current, 1, 0, 0); You can just use a different parameter for each phase and for each framenumber. I hope this helps you. Good luck !! Rachid |
The Following User Says Thank You to Rachid Kolfin For This Useful Post: | ||
Shanon Loughton (04-06-2009) |
#4
|
||||
|
||||
Carsten,
You can use if() else if() chains in Flexscript and C++ just fine. This code is just fine: int fred = 3; if(fred == 1) { pt("fred is 1\n"); } else if(fred == 2) { pt("fred is 2\n"); } else if(fred == 3) { pt("fred is 3\n"); } For a refresher on basic C++ syntax: http://www.sscnet.ucla.edu/geog/gessler/borland/cpp.htm Everything on that page except the goto/exit works in Flexscript the same way. As for why Shanon's code crashes, Rachid explained it pretty well. |
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post: | ||
RalfGruber (04-06-2009) |
#5
|
||||
|
||||
Use Custom Draw Code trigger
Rather than create your own chain of events using the OnMessage trigger, you should consider using the Custom Draw Code trigger. It's a naturally reoccurring event that only fires when there is a 3D view window open. Use a variables (e.g. labels) in your code to reference the start time, and duration of the animation phase.
|
The Following 2 Users Say Thank You to Cliff King For This Useful Post: | ||
Shanon Loughton (04-06-2009) |
Thread | Thread Starter | Forum | Replies | Last Post |
Displaying the simulation time with the various date/time formats. | Regan Blackett | Tips and Tricks | 12 | 11-12-2012 08:01 AM |
State report based on the operational time | Simon Farsah | Q&A | 8 | 06-07-2011 01:42 AM |
Image Swap Based on Position Logic | William Clausen | Q&A | 8 | 08-06-2008 11:42 AM |
Make sure you stop model with the stop button before collecting state based statistics | Paul Dowling | Tips and Tricks | 2 | 06-10-2008 08:10 AM |
Inter Arrival Time by Time of Day Mod | Brandon Peterson | Tips and Tricks | 0 | 04-23-2008 11:13 AM |