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 |
|
Downloads |
Flexsim Student Forum Forum for discussion for Flexsim Students using the Flexsim Textbook. |
#1
|
|||
|
|||
onmessage function in SendTo port function
Hi all,
Please take a look at my coding, and I put it in the "Send To Port" of a queue (let's call it "Queue1"). treenode item = parnode(1); treenode current = ownerobject(c); int message = msgparam(1); for (int i = 1; i <= 5; i++) { if (message == i) { treenode downstream = outobject(current,i); openinput(downstream); return i; } } Imagine there are 5 downstream stations which will send a message to this Queue1 after a period of time, one by one, and not sending the message at the same moment. Question: Can someone advise me on what is wrong with the above coding? Or what should I do so that the Send To Port function can behave like OnMessage Trigger, as in, everytime it receives a message, it will run the for-loop and then return i. 'i' would be the values associating with the output port where the messages from. I don't wish to use msgsendingobject() because the downstream stations, which would send a message, does not directly connect to this Queue1. Second question (not related at all to the above question), In Python Programming language, there is elif function. But as I read the user manual in Flexsim, it never mentions about elif. Can someone please teach the basic coding to obtain elif function for Flexscript? So sorry for my poor programming skill. Thank you so much for your help. Hendry |
#3
|
||||
|
||||
Hi Hendry,
there are some mistakes in your code. The msgparam command works only in the OnMessage Trigger. But you can store the value of your incoming message in a Label of your queue in the OnMessage Trigger and evaluate this label in the function Send To. There is a runtime problem too when you open the input of your receiving object and sending the item to it at the next code line, because the engine does not recognize the change of the availability of the input ports. The Send To function expects, before releasing an item, that the input port is already available. You expects a behaviour of the flexsim engine and then you write a source code without knowing what the engine does. But you can find all this knowledge in the manual. Please read it. Then build a simple model to understand how the flow works, and then with a proved knowledge adapt this to your model. Don't guess or assume, instead build models on knowledge. Jörg Last edited by Jörg Vogel; 05-27-2015 at 11:40 AM. |
The Following User Says Thank You to Jörg Vogel For This Useful Post: | ||
hendry teo (05-28-2015) |
#4
|
|||
|
|||
Hi Jorg
Many thanks to your reply for the explanation. I will give a try to your suggestion by storing the incoming message in a Label of the queue. This would probably help me alot in my model. Totally got you. Well, you were true that I sometimes do not build the model on knowledge, but due to the time constraint, what I can do is to give a try and learn along the way Thanks again! |
#5
|
||||
|
||||
Quote:
Code:
if (content(item) == 2) { colorred(item); } else if (content(item) == 3) { colorgreen(item); } else { colorblack(item); } |
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post: | ||
Jörg Vogel (05-27-2015) |
#6
|
||||
|
||||
another possibility for the elif is the switch function with case statements. That c++ construct also works in Flexscript.
|
The Following User Says Thank You to Steven Hamoen For This Useful Post: | ||
hendry teo (05-28-2015) |
Thread | Thread Starter | Forum | Replies | Last Post |
Freeoperators function | Lucie Lerivrey | Q&A | 1 | 08-30-2012 11:26 AM |
function opavailable | MoserGaudenz | Q&A | 1 | 02-28-2011 05:19 AM |
Recorder function | mawajed | Q&A | 1 | 03-26-2010 07:23 AM |
How to use bernoulli function | nie wuwei | Q&A | 2 | 08-08-2009 02:41 AM |
Print function | David Chan | Gripes and Goodies | 0 | 05-21-2008 09:38 PM |