Access with jd to an specific object in foreach [SOLVED]

According to the example of “Javascript in web games”, “Custom javascript code can access to the specified objects and to the scene:” but in the case of a “for each object event” how can access to that object?

I tried with the variable “objects” but it is not defined :confused:

EDIT & SOLVED: Ok, if there is any object selected cause a condition it executes the javascript but objects is not defined. I only have to detect if it is not defined (not undefined, null or size 0, just not defined).

Doing (code from the example) :

for(var i = 0;i<objects.length;++i) { objects[i].setAngle(Math.cos(runtimeScene.getTimeFromStart()/100)*90); }
in a JS event is already equivalent to a “for each” event. :wink:

Or, you can do it with a “For each” event, put the JS event inside and do the things you want to do with objects[0] (GDevelop still use an array of object even if the For Each event guarantees that its size will be 1).

No no, I was using the For each event but inside there there was a condition, if the object doesn’t accomplish the condition it says object is not defined (instead of an array with length 0 or something else).

So I did
For each event ObjectX
contidion
subevent code javascript
if(typeof objects != "undefined"){ [...] }

Ok :slight_smile: