Calling to a plugin function inside a game Event

I've created a plugin with this simple function:
Code:
(function() {
    var logTest = function() {
        console.log("test!");
    }
})();

In an event, I put inside the Script dialog: logTest();

Run the game and... "logTest is not defined".

Edit: If I put the global function outside the IIFE it works.
Yes, the var keyword defines a local variable on the enclosing block.

Several options here:
  1. Define your method globally from within the IIFE, either implicitly:
    Code:
    (function() {
      logTest = function() { console.log("test!"); };
    })();
    ...or explicitly:
    Code:
    function() {
      window['logTest'] = function() { console.log("test!"); };
    })();
  2. Define it as a member of an existing object and then call it via that object, e.g.
    Code:
    var myNamespace = {};
    function(obj) {
      obj.logTest = function() { console.log("test!"); };
    })(myNamespace);
    
    myNamespace.logTest();
  3. Put it outside the IIFE.

Original thread: https://forums.rpgmakerweb.com/threads/calling-to-a-plugin-function-inside-a-game-event.108582/