title: using requireJS to dynamically load js files
body: <p>I'm creating a RPG. I would like to dynamically load NPC dialog js files depending on the current level.</p>
  
  <p>Originally, I was doing <code>&lt;script type="text/javascript" src="js/npc_dialog_level_1.js"&gt;&lt;/script&gt;</code> at the top of my game.js file... but don't want to keep doing that for each npc_dialog.js file.</p>
  
  <p>I would rather do something like:</p>
  
  <pre><code>if (map == 1) {
     require(js/npc_dialog_level_1.js);
  if (map == 2) {
     require(js/npc_dialog_level_2.js);
  </code></pre>
  
  <p>I was following <a href="http://requirejs.org/docs/start.html#get" rel="nofollow">requireJS</a>'s tutorial, but I'm not clear on:</p>
  
  <p><strong>a)</strong> The download requireJS doesn't include the helper/utils.js folder and file specified in the example:</p>
  
  <pre><code> project-directory/
      project.html
      scripts/
          main.js
          require.js
          helper/
            util.js
  </code></pre>
  
  <p><strong>b)</strong> How to use the require function: <code>require(["helper/util"], function(util) {</code>
     On map change, I'd like to just place the path to the associated <code>npc_dialog_level.js</code> file. Where do I put the Require code, and what do I pass into it to load the correct js file?</p>
  
  <hr>
  
  <p>Each npc_dialog_level file contains js object. I am using that in my game to read dialog</p>
  
  <pre><code>var dialog = {
  
  quests : {
      Lee : {
          "1 - Introductions" :
  </code></pre>
  
  <hr>
  
  <p>Update:</p>
  
  <p>I tried:</p>
  
  <pre><code>//load NPC dialog given the map
  loadNpcDialog : function (dialogNumber) {
      require("npc_dialog_level_" + dialogNumber + ".js", function(dialog) {
      //  log(dialog);
      });     
  },
  </code></pre>
  
  <p>Gives:</p>
  
  <pre><code>Uncaught Error: Invalid require call
  http://requirejs.org/docs/errors.html#requireargs require.js:166
  </code></pre>