title: My code won't work unless each part is placed in a separate button?
body: <h2>The exact problem</h2>
  
  <p>I found out that if I have these two parts of codes written after each other in one place i.e. one button the functions related to the block <code>wait</code> (i.e <code>wait.get()</code> and <code>wait.size()</code>) won't work. However, If I have each part in a separate button everything works perfectly.   </p>
  
  <h2>PART 1</h2>
  
  <p>1- Directing agents <code>households</code> to <code>enter</code> the flowchart </p>
  
  <pre><code>for (Agent i: households){
      enter.take(i);}
  traceln("this is 1");
  </code></pre>
  
  <p>(<code>enter</code> here is linked directly to <code>wait</code> ) then..</p>
  
  <pre><code>traceln("this is the current wait size: " + wait.size());
  </code></pre>
  
  <p>At this stage, the agents supposedly are in wait. However, <code>wait.size()</code> returns  <code>this is the current wait size: 0</code>. Although the agents are showing in wait at the view window <a href="https://i.stack.imgur.com/2ICCF.png" rel="nofollow noreferrer">which looks like this</a>. These agents are not accessible using functions like wait.get() or wait.size()</p>
  
  <h2>PART 2</h2>
  
  <p>Therefore, this part which has to run after part 1 is not working</p>
  
  <pre><code>for (int i =0 ; i&lt;wait.size() ; i++){
      collection_main_households.add(wait.get(i).getIndex());
  }
  wait.freeAll();
  </code></pre>
  
  <p>In short, these codes will only work in separate buttons but, I want them to work if written after each other. </p>
  
  <h2>further information about the model</h2>
  
  <p>Basically, The model is for residential mobility among some districts. 
  At the <code>stratup</code> stage in <code>main</code>, I construct and link each familiy, based on a table contains the number of members and their ages. </p>
  
  <p>The way these families are constructed is based on a <code>household</code> agent that is used as a core for <code>linking</code> and moving its family members ( <code>father</code>, <code>mother</code> and <code>children</code>). So, if I moved the <code>household</code> from A to B a <code>message</code> will be sent to its members directing them to move from A to B.</p>
  
  <p>The code up is just for the first two steps after households are completely formed and ready to be located in their original locations. The process is as follows : </p>
  
  <ol>
  <li>I use <code>enter</code> to get the households into the flowchart</li>
  <li>Then, all gathered in the temporary status <code>wait</code> before they go free.</li>
  <li>With the <code>wait.free(this)</code> command I use the <code>selectOutPut(IN/Out)</code> to distribute these <code>households</code> to their original locations.</li>
  <li>When a <code>household</code> enters his location (in this case a new <code>waitID..</code>)  I <code>send a message</code> to all its connected members asking them to go to the same destination using the same commands of <code>enterID.take(this)</code> and <code>waitID.free(this)</code>. At this points all these components (<code>household</code> and its members of <code>father</code> , <code>mother</code> and <code>children</code> ) should be in the same <code>node</code>.</li>
  <li>I repeat the process in the case of the a <code>household</code> is willing to change its location.</li>
  </ol>
  
  <p>I used the <code>collections</code> to go around the problem of dynamically changing and accessing the <code>Hash Lists</code> generated by using <code>wait.waitingEntities</code>. What matters is that If <code>wait</code> takeing simultaneously from <code>enter</code>  what is the way to address that?</p>
  
  <p><a href="https://i.stack.imgur.com/CuT5F.png" rel="nofollow noreferrer">screen capture</a></p>
  
  <p>Thanks in advance.</p>