title: Variables Becoming Undefined After being passed through function - NodeJS
body: <p>Im trying to write two functions to work together, but when I pass through a variable from the first function to the second function, it comes out as undefined. Here are the functions:</p>
  <pre><code>function StartAlerter(){
      var rawdata = fs.readFileSync('./events/' + tevent)
      var cJSON = JSON.parse(rawdata)
      var notifier = cJSON.notifier
      var tdate = cJSON.epochtime
      var messagefile = JSON.parse(fs.readFileSync('./notifier/' + notifier, function(err){
          if(err) console.log('Issue with loading message file, setting to null'.red)
          console.log('Message file failed to load: ' + './notifier' + notifier)
      }));
      var messagecontent = messagefile.text.toString()
      waitforsend(tdate, messagecontent)
  }
  </code></pre>
  <p>Second Function:</p>
  <pre><code>function waitforsend(tdate, messagecontent) { //https://stackoverflow.com/questions/22125865/wait-until-flag-true
      cdate = Math.floor(new Date().getTime())/1000 - 18000
      console.log(tdate)
      if(cdate &lt;= tdate) {
         setTimeout(waitforsend(), 100);
      } else {
          console.log(messagecontent)
          client.channels.cache.get(eventchannelid.toString()).send(messagecontent)
      }
  }
  </code></pre>
  <p>They have the proper values in StartAlerter(), but become undefined in waitforsend(). Why is this?</p>