title: order of calling functions javascript
body: <p>I have three functions in javascript, <code>parsing</code>, <code>init</code> and <code>animate</code>. <code>Parsing</code> has to be called first because without it, the <code>positions</code> array isn't modified, which the function <code>init</code> needs. Weirdly enough, animate needs the <code>controls</code> variable created by <code>init</code> but they used to be called at the same time and it worked before. I've tried every combination possible of calling the functions, but either <code>controls</code> is undefined or <code>positions</code> is. This is the last iteration of my code. </p>
  
  <pre><code>var positions = [];
  parsing();
  
  function parsing() {
      fetch('Petit_film_256_atomes.txt').then(response =&gt; response.text()).then(text =&gt; {
          const arr = text.split('\n')
              .map(line =&gt; line.trim())
              .map((arr) =&gt; arr.split(' '))
              .map(([size, x, y, z]) =&gt; ({ 
                    size: Number(size), 
                    x: Number(x), 
                    y: Number(y), 
                    z: Number(z) 
              }));
              while (arr.length &gt; 0) {
                  positions.push(arr.splice(0, size).slice(2));
              }
          init();
          animate();
      })
  }
  ...
  function init() {
      renderer = new THREE.WebGLRenderer({antialias:true});
      renderer.setSize(WIDTH, HEIGHT);
      document.body.appendChild(renderer.domElement);
      ...
      console.log(positions);
      for (var i = 0; i &lt; 256; i++) {
          atom = sphere.clone();
          atom.position.set( positions[0][i].x, positions[0][i].y, positions[0][i].z );
          scene.add( atom );
          group.push( atom );
      }
      ...
      controls = new THREE.OrbitControls(camera, renderer.domElement);    
  }
  
  function animate() {
       requestAnimationFrame(animate);
       renderer.render(scene, camera);
       controls.update();
  }
  </code></pre>
  
  <p>Also, the <code>console.log(positions)</code> shows a non empty array yet the error displayed is still that <code>positions</code> is undefined. Anyone have an idea why?</p>