How to use object variables in javascript

Hi, I’m using javascript in gdevelop, but I can’t use object variables, for example I want if the object variable is 5, all objects with that value will be hidden, in the events this is easy to do, but java script I can only make the value equal to 1 and if it is applied to the object with value 1, but only to one instance, if I put 2 instances with the value 1,and I try to apply the actions it only applies to one instance. I hope you understand what I mean, and thanks in advance

I just realized that it applies to a single instance by this: const player = objects[0]; This applies to the first instance of the scene, but if I put: const player = objects[1]; It refers to the second instance, so how do I apply this to all instances of the object?

I’d suggest checking out the ‘Javacript blocks in platformer’ example. It should run through what you want within the enemies management section. (loops through objects, sets behaviors/opacity/etc).

You’ll still need to get/set your variables within the forEach().

1 Like

I already reviewed this example, and I learned a few things, but what I want is to apply actions to all instances of the object

I’m going to try to use foreach to see how it goes and thanks for the advice