How to call a JS function under 'External Events' from 'Functions/Extensions'

Hello.

I’m using ‘external events’ as custom JS library for a specific functionality. This file is included in my current working events sheet. I need to access the functions in this library which are defined as ‘Functions/Extensions’ from various location in my events sheet. Unfortunately, this doesn’t seem to work. I get a log message for 'undefined reference.

This is what I have in the ‘External Events’:
function testlog(){
// Function to test access to local function
console.log(“it works!”);
}

An this is how I’m trying to call it when defined as ‘Functions/Extensions’:

Any ideas if this is actually supported or how I should be doing it?

Thanks,
Stelios

All JS code in JS event have strict mode.
You need pass your functions in global for use it.
You can take a look on the gamepad extension, i’ve used JS event and i share my code in gdjs._extensionController

Hello.

I had a look at that code, but only see that the code is self-contained in an ‘External Event’ and you don’t call functions contained in that code from other places. Am I missing something?

You can do

gdjs._extensionNameHere.myFunction = function () {
//your code
};

gdjs._extensionNameHere.myFunction();

It seems I managed to get it to work by switched the function declarations:

testlog = function(){
// Function to test access to local function
console.log(“it works!”);
}

It seems that I’m able now to call the function without any problems. It’s still not clear to me why this works.

Looking at you code, I saw that you are using variables, such as Axes_0, Axes_1 and you update them with any values you get from the game pad. I couldn’t find those variables been declared either in the global or in the scene. How is this working?

I use Gamepad API,

But if you talk me of External Events, me i talk about extension.
Prefer use the extension in “Functions/Behaviors”
The example Gamepad is not yet updated.

You should know that the code in javascript events is executed 60 times per second. or depending your custom FPS