ATTENTION

This 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

Go Back   FlexSim Community Forum > FlexSim Software > Flexsim Student Forum
FAQ Downloads Calendar Search Mark Forums Read

Flexsim Student Forum Forum for discussion for Flexsim Students using the Flexsim Textbook.

Reply
 
Thread Tools Display Modes
  #1  
Old 05-26-2015
hendry teo
Guest
 
Posts: n/a
Downloads: 41
Uploads: 0
Default 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
Reply With Quote
  #2  
Old 05-26-2015
hendry teo
Guest
 
Posts: n/a
Downloads: 41
Uploads: 0
Default 1 more piece of info

sorry, I forgot to mention that each of the 5 stations would send a different message parameter, such that, station 1 sends param 1, station 2 sends param 2, and so forth.

thanks!!
Reply With Quote
  #3  
Old 05-26-2015
Jörg Vogel's Avatar
Jörg Vogel Jörg Vogel is offline
Flexsim User
 
Join Date: Sep 2007
Location: Hannover, Germany
Posts: 643
Downloads: 35
Uploads: 0
Thanks: 802
Thanked 665 Times in 410 Posts
Rep Power: 636
Jörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond reputeJörg Vogel has a reputation beyond repute
Default

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.
Reply With Quote
The Following User Says Thank You to Jörg Vogel For This Useful Post:
hendry teo (05-28-2015)
  #4  
Old 05-27-2015
hendry teo
Guest
 
Posts: n/a
Downloads: 41
Uploads: 0
Talking

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!
Reply With Quote
  #5  
Old 05-27-2015
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1169
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

Quote:
Originally Posted by hendry teo View Post
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?
Use else if {}

Code:
if (content(item) == 2) {
        colorred(item);
} else if (content(item) == 3) {
        colorgreen(item);
} else {
        colorblack(item);
}
Reply With Quote
The Following 2 Users Say Thank You to Phil BoBo For This Useful Post:
hendry teo (05-28-2015), Jörg Vogel (05-27-2015)
  #6  
Old 05-27-2015
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 678
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

another possibility for the elif is the switch function with case statements. That c++ construct also works in Flexscript.
Reply With Quote
The Following User Says Thank You to Steven Hamoen For This Useful Post:
hendry teo (05-28-2015)
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
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


All times are GMT -6. The time now is 01:29 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.