title: Variable is undefined/out of scope
body: <p>This is a scope issue, correct?</p>
  
  <p>EDIT: <a href="http://jsfiddle.net/RPwLK/7/" rel="nofollow">http://jsfiddle.net/RPwLK/7/</a></p>
  
  <p>On line 38 of the following function, where displayBossMessage() is called by itself, the variable "boss" seems to be out of scope. It should contain the name (string) of the current boss, and when the function is called, it should put it back in the "boss" argument.</p>
  
  <p>But boss seems to always be undefined. I've tried creating a variable right before the jQuery listener is created to see if it would be within scope, but it seems as if it isn't.</p>
  
  <p>Or maybe I'm just having a slow day. ;p</p>
  
  <pre><code>function displayBossMessage(boss,message,options,timer){
      boss = bosses[boss];
  
      //clear any possible lingering text/buttons
      $(boss.messagebox).text('');
      $(boss.optionsbox).text('');
      displayMessage_CurrentBoss = boss;
  
      //if no options provided, set a default "continue" button
      if(options == ''){
          options = {
              'default' : {
                  'text' : 'Continue',
                  'func' : function(){}
              }
          }
      }
  
      $('#container div').hide();
      $(boss.div).fadeIn(1500);
  
      writeMessage(message,$(boss.messagebox),0);
  
      setTimeout(function(){
          $(boss.optionsbox).fadeIn(1000);
      },3000);
  
      //"listen" for a choice
      var i = 0;
      for(option in options){
          $(boss.optionsbox).html($(boss.optionsbox).html() + '&lt;button name="'+ i +'"&gt;'+ options[option].text +'&lt;/button&gt; &amp;nbsp;');
  
          $(document).on('click', (boss.div)+' button[name="'+i+'"]', function(){
              options[option].func();
  
              //close message screen or show defined response
              if(typeof options[option].response != 'undefined'){
                  displayBossMessage(boss,options[option].response,'',true);
              }else{
                  $(boss.div).hide();
                  $('#container div').fadeIn(1500);
              }
  
          });
      }
  
      if(timer){
          //if they are afk/don't click after a minute, do it for them
          setTimeout(function(){
              $(boss.div+' button[name="0"]').click();
          },60000);
      }
  }
  </code></pre>
  
  <p>Hope I'm not being completely oblivious and missing something so simple.</p>
  
  <p>*<em>Edit: Bosses variable (is global) *</em></p>