Use Javascript object from external Library PROBLEM

Hi All!
I just want to use a chess Javascript library ,but i am having a problem creating an instance of thay library :

scene.preload = function() {
    this.load.script('chess', 'assets/js/chessboard-1.0.0.min.js');
}; 

scene.create = function() {
    let board=new Chessboard();
}

Looking at the error in the console,Phaser it s trying to do the following:
new window.Chessboard () ,so i get an error .
It s like a scope problem.

Could you give me a hand with this? Thanks in advance!!

Hi,

I’m afraid this is nothing to do with Phaser, really. You (or in this case chessboard.js) is the one that controls which scope it will inject its class in to.

If you do new Chessboard() it will expect for Chessboard to exist in the current or global scope. Phaser will never automatically add a scope for you, it will just obey the standard laws of JavaScript in terms of the context.

Typically, a Phaser scene can access window directly, without needing to add the window prefix, however, this depends 100% on how you have set-up your project, how your files are being bundled and imported, etc. If window.Chessboard works and Chessboard doesn’t, then it’s almost certainly to do with the way you’ve set-up the project (or Scene) itself.