[SOLVED] Javascript link two object

Hi, how can i “Link” two object by javascript code ?
I don’t find nothing about it.

Right-Click “Add a new event” than you can choose Javascript, and on the top you can choose your Object

More Infos: JavaScript Code events [GDevelop wiki]

Thanks, but you showed how i can open javascript tool.
I ve opened it. Now i’m writing a function, and in the code i’d like to “link” two object.
This is my function:

First of all, note that GDevelop isn’t meant to be used only through JavaScript. Normally, you don’t need it, and should prefer the event sheet as GDevelop is designed with it in mind more than javascript developers.

Here is how you would do it:

const enemy = objects[0];
const gun = runtimeScene.createObject('Gun_Object');
const manager = gdjs.LinksManager.getManager(runtimeScene);

manager.linkObjects(enemy, gun)

Note that in your screenshot there is an issue. You use object, but the passed object is named objects. It also is an array of all instances of the objects and not a single reference to an instance.

1 Like

Thank you @arthuro555

Thanks, this info helped me today!