Call instance coordinates in expression

How do I…

Pass an instance’s Y coordinates to an expression.

Longer description: I want to move an object (pink square instance) in my scene editor to determine where a block falls based on my custom function. I’d like the function’s x and y values to call the pink block’s x and y coordinates. This way I can move the block around and it auto-updates.

What is the expected result

In the “Y” value of my function, I call the Y value of an object instance in my scene editor.

What is the actual result

I cannot find this expression or one that would work. I understand how to do it through conditions, but I just want the value in the expression.

Related screenshots


Here is my custom function.


Here is my scene. I’d like to pass along the Y value of the highlighted instance.

Thanks :v:

I’m a tad confused here. Are you wanting to move the object in the scene editor and pass that value to the function while in the GDevelop scene editor? That can’t happen, because the function doesn’t operate until the game is run.

If it’s at run time, then what’s stopping you from passing fallingBlockLocation.Y()?

If I’ve misunderstood, then could you try explaining it a bit more?

1 Like

At runtime is fine! And yes, fallingBlockLocation.Y() would work but how do I differentiate between the two instances when I call it in the expression?

Basically, when I call the custom function at different times, I want it to drop a block at different fallingBlockLocation.y coordinates by picking different ones. Do I need to set up a variable ID for them and add that to the expression?

You can use an ID as you suggested. You could also position, proximity to a point/object or a randomly picked one (there is a condition to pick a random object instance).

1 Like