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 06-09-2011
shashanktrivedi shashanktrivedi is offline
Flexsim User
 
Join Date: Apr 2011
Posts: 59
Downloads: 26
Uploads: 0
Thanks: 26
Thanked 16 Times in 3 Posts
Rep Power: 122
shashanktrivedi will become famous soon enough
Default treenode compilation error

Hi,

The below code is not getting compiled
-------
for loop{

createinstance(node("/NetworkNode",library()),model());
treenode networknode3= last(model());
}
contextdragconnection(networknode3,node("/Transporter3",model()),"A");
-------
However this code gets compiled
-------
treenode networknode3;
for loop{

createinstance(node("/NetworkNode",library()),model());
networknode3= last(model());
}
contextdragconnection(networknode3,node("/Transporter3",model()),"A");
-------
Just defining treenode outside for loop, script runs fine.

Not sure why, Kindly advise.

Regards
Shashank Trivedi
  #2  
Old 06-09-2011
Alex Christensen Alex Christensen is offline
Flexsim Technical Support
 
Join Date: Nov 2007
Location: Provo, UT
Posts: 96
Downloads: 41
Uploads: 8
Thanks: 29
Thanked 141 Times in 56 Posts
Rep Power: 298
Alex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to behold
Default

If you use networknode3 outside of the for loop, then you need to declare it outside of the for loop. If not, then the scope of the variable is limited to the for loop and it will only be able to be used within the for loop and it will need to be initialized every time you go through the loop. That's also how variables behave in C++.
The Following User Says Thank You to Alex Christensen For This Useful Post:
shashanktrivedi (06-15-2011)

Tags
treenode



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.