Archive 17/01/2023.

[SOLVED] Setting a Vector2 individual property

Mike

Trying to scale a sprite (healthBar) in lua using one of these lines of code, I experience a weird behavior:

		healthBar.scale.x = healthBar.scale.x - 1 / 10
		healthBar.scale = healthBar.scale - Vector2(1 / 10, 0)

Both lines return the correct scale but only the last one ‘updates’ the UIElement’s scale.

Same code in AngelScript complains that scale.x is read-only.

aster2013
It look like:
[code]
    Vector2& scale = healthBar->GetScale();
    scale.x = scale.x - 1.0f / 10.0f;
[/code]

But when you call:
[code]healthBar.scale = healthBar.scale - Vector2(1 / 10, 0)[/code]]
It look like:
[code]
    Vector2& scale = healthBar->GetScale();
    healBar->SetScale(scale - Vector2(1.0f / 10.0f, 0.0f));
[/code]

    

It will call healthBar:GetScale(), then set the scale's x value.

It look like:

    Vector2& scale = healthBar->GetScale();
    scale.x = scale.x - 1.0f / 10.0f;

But when you call:

It look like:

    Vector2& scale = healthBar->GetScale();
    healBar->SetScale(scale - Vector2(1.0f / 10.0f, 0.0f));

It will call healthBar:GetScale(), then set the scale’s x value.

Mike

Thanks Aster, now I understand what’s going on.