Input an object height instead of a number in an expression

Hello everyone,

Can’t figure this one out:

i’m trying to create an object above another but since the height of the objects vary sometimes as I work on them, I’d like it to be a little more dynamic.

Say I have obj1 and obj2, both 100px in height.
I’ll do: create obj1 at 0;obj2.Y()-100

So that works, boom obj1 is on top of obj2

What I’d like to do but doesn’t work is this:
create obj1 at 0;obj2.Y()-(obj1.Height())

Thought that would be clever when obj1 height changes.

Also tried to register the height as an obj variable in obj1 but that gave me the same result, which is none.

I’m clearly calling on the height variable in a wrong way because it doesn’t register as “100px” (in this instance).

Could you please help understand this? I scoured through the variable page but it’s still quite opaque for me in some areas

Many thanks in advance!

Hello @aucoeurdemage
I suggest you to split the command into two commands:

1 Like

My saviour!

Beautiful workaround and great overall lesson for me, separate the lines, don’t ask Y() (ahah puns!)

Thank you very much indeed JumpinGJ. (I must ask, what is GJ, since you’re jumping in it? Hope it’s safe to do so! lol)

1 Like

What Jumpingj suggest will work
But sometimes you wanna change position of something without doing it only once like at beginning of scene or with trigger once

Then
Lets imagine you have objectA and objectB

And you want to place objectB somewhere in relation to objectA

And so instead of subtract you also go with set to
BUT

ObjectB

Above objectA
Change Y pos of objectB set to ObjectA.Y()-ObjectB.Height()

Below objectA
Change Y pos of objectB set to ObjectA.Y()+ObjectA.Height()

Right from objectA
Change X pos of objectB set to ObjectA.X()+ObjectA.Width()

Left from objectA
Change X pos of objectB set to ObjectA.X()-ObjectB.Width()

1 Like

Sexy!

It’s kinda what I wrote in my code, right?

0;obj2.Y()-obj1.Height()

But I used Create an Object, instead of change Position (of just Y, in this case, for me)

So basically, create the object, THEN play with position and there you can start using relative position from one object to another. Beautiful.

I wonder why it doesn’t work when using “create object” and just change position.

Ah! Maybe because the object you reference and want to subtract to its position, its height, doesn’t exist yet. So it can’t be referenced at the “create object” but after it can, thus changing its position works. Cool stuff!

This Worked, thank you so much both of you.

Conclusion:

  1. Create object wherever
  2. Move to position you want with some cool relativity between both objects (the original one and the newly created)