title: Passing additional parameters to an Apps Script event object
body: <p>I'm having a lot of headaches with callbacks and scopes in Apps Script. I have the following function, that creates a Gmail Add-On section with a checkbox for each attached file on the currently open email:</p>
  
  <pre><code>function createAttachmentsSection( attachments ){
  
    var widget = CardService.newSelectionInput()
      .setFieldName( 'selectedFiles' )
      .setType( CardService.SelectionInputType.CHECK_BOX )
      .setOnChangeAction(
        CardService.newAction()
          .setFunctionName( 'checkboxAltered' )
      );
  
    for ( var i = 0 ; i &lt; attachments.length; i++ )
      widget.addItem( attachments[i].getName(), '' + i ,  true )
  
    return CardService.newCardSection().addWidget( widget );
  }
  </code></pre>
  
  <p>Everything is displayed as expected, but I want the user to be also able to select which files he wants to uncheck for later processing.
  In my checkboxAltered function I want to handle user selection input actions, which is the only way to go (as far as I've learned from the documentation. Please tell me if I'm wrong!). It's currently an empty function, only used to check how little I understand:</p>
  
  <pre><code>function checkboxAltered( e ){
  
    Logger.log( e );
    Logger.log( selections.length );
  }
  </code></pre>
  
  <p><code>e</code>, the event object, is always <code>undefined</code> here. And <code>selections</code>, a (previously initialized and checked) global bool array with an item for each attachment, is always simply <code>[]</code> inside checkboxAltered.</p>
  
  <p>What am I doing wrong?
  How can I use setParameters( Object ) to tell inside the callback function which checkbox was clicked by the user?
  Are global variables not accessible from callback functions?</p>