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 > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 10-16-2015
Heather Ulrich
Guest
 
Posts: n/a
Downloads: 0
Uploads: 0
Default Coding assistance needed

I'm trying to write a couple lines of code to change the name of an object from one name to another through an exit method.

Currently this is what I have

if (part_name !="Blue")
{
setname(item,"Red");
}

The first line of code is read, but nothing happens.

Another item I'm needing help with is how to move a part from the separator to the combiner on certain parts that need to go through my system twice. Not sure how to start the code for this issue.

If there is a good place for example code for these type of items I would appreciate some reference documents for I know code in other simulation software, but not FlexSim.

Thanks - Heather
  #2  
Old 10-16-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: 684
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

if you want to compare text you have to use the function "comparetext()". So your lines should read:
if( !comparetext( part_name, "Blue") )
{
setname(item,"Red");
}

For the other question, can't you just use an output port and send that back to the entry of another object?
The Following User Says Thank You to Steven Hamoen For This Useful Post:
Sebastian Hemmann (10-20-2015)
  #3  
Old 10-16-2015
Heather Ulrich
Guest
 
Posts: n/a
Downloads: 0
Uploads: 0
Default

Steven - That code was read, but it still does change the name of the part. Not sure why for the name matches perfectly and should change without an issue.
  #4  
Old 10-16-2015
Heather Ulrich
Guest
 
Posts: n/a
Downloads: 0
Uploads: 0
Default

I state that the part that I'm trying to look at the name of is on a pallett
  #5  
Old 10-16-2015
Ben Wilson's Avatar
Ben Wilson Ben Wilson is offline
Flexsim Consultant, Super Moderator
 
Join Date: Jul 2007
Posts: 82
Downloads: 352
Uploads: 6
Thanks: 30
Thanked 159 Times in 43 Posts
Rep Power: 256
Ben Wilson is a glorious beacon of lightBen Wilson is a glorious beacon of lightBen Wilson is a glorious beacon of lightBen Wilson is a glorious beacon of lightBen Wilson is a glorious beacon of light
Default

Hi Heather,

Do you know if the item referenced in your code is the item for which you want the name to change?

One thing you could do is step through your code as it's executed and watch the local variables to see if they are actually pointing to the objects you think they are.

Put a break point in your trigger code by clicking in the margin left of the code text. This will put a red circle (a break point) in your code. The next time that code is executed, execution will stop at the break point and show you a yellow arrow where the execution is currently paused.

New tool panes will also have opened up to show you local variables, watch variables, and the call stack. There will also be code stepping buttons at the top of your paused code window to step to the next line, or into a function, etc.

Let us know what you find out.
The Following 2 Users Say Thank You to Ben Wilson For This Useful Post:
Sebastian Hemmann (10-20-2015)
  #6  
Old 10-19-2015
Heather Ulrich
Guest
 
Posts: n/a
Downloads: 0
Uploads: 0
Default

Ben - Thanks for your assistance. I have been able to get the code to work to change the name of the item.
  #7  
Old 10-19-2015
Matt Long Matt Long is offline
FlexSim Development
 
Join Date: Apr 2012
Posts: 66
Downloads: 37
Uploads: 29
Thanks: 2
Thanked 150 Times in 40 Posts
Rep Power: 192
Matt Long is a glorious beacon of lightMatt Long is a glorious beacon of lightMatt Long is a glorious beacon of lightMatt Long is a glorious beacon of lightMatt Long is a glorious beacon of light
Default

In 7.5 we made a change to make string comparisons work with the standard == operator.

if (getname(item) == "MyItem")

This is a valid comparison.
The Following 4 Users Say Thank You to Matt Long For This Useful Post:
Steven Hamoen (10-20-2015)


Thread Thread Starter Forum Replies Last Post
How to write coding for that? stmyint Container Terminal (CT) Library 5 10-29-2012 08:03 PM
Coding problem Liang Wen Yin Q&A 4 08-13-2012 04:49 PM
Questions on coding Jack Lai Q&A 6 02-07-2012 12:04 AM
Need help for coding on lifts. chrisquek Q&A 5 11-25-2008 03:00 AM
A pitfall in Flexsim coding AlanZhang Gripes and Goodies 7 05-16-2008 03:37 PM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.