Can't receive correct coordinates of Node after gui.animate() (SOLVED)

Help me please.
This is a part of code:

if message_id == hash("work")
	then
		qwe = gui.get_position(self.blue_fills[10])
		dt = 10
		gui.animate(self.blue_fills[1], gui.PROP_POSITION, vmath.vector3(qwe.x, qwe.y + 20, qwe.z), gui.EASING_INOUTSINE, dt)
		qwer = gui.get_position(self.blue_fills[1])
		pprint(qwer)
	end

When I send “work” first time qwer returns vmath.vector3(895.71166992188, 275.5192565918, 0) and if i send “work” again qwer returns vmath.vector3(895.71166992188, 439.5192565918, 0).
How can I receive correct coordinate of Nodes after gui.animation

Look your array index

The first one it is 10

After 1 and 1again.

Is it which you really want to do?

{
1 = box@(895.71166992188, 275.5192565918, 0),
2 = box@(895.71166992188, 291.5192565918, 0),
3 = box@(895.71166992188, 307.5192565918, 0),
4 = box@(895.71166992188, 323.5192565918, 0),
5 = box@(895.71166992188, 339.5192565918, 0),
6 = box@(895.71166992188, 355.5192565918, 0),
7 = box@(895.71166992188, 371.5192565918, 0),
8 = box@(895.71166992188, 387.5192565918, 0),
9 = box@(895.71166992188, 403.5192565918, 0),
10 = box@(895.71166992188, 419.5192565918, 0),
}
This is array

I need to receive vmath.vector3(895.71166992188, 439.5192565918, 0) after animation.
But I receive correct position only after second message. I want to receive it on first message

The execution of code after your call to go.animate() will not wait until the animation is done. When you call go.animate() the animation will start and the code will continue to execute and you’ll still read the original position. You need to use the go.animate() callback function:

if message_id == hash("work") then
	local qwe = gui.get_position(self.blue_fills[10])
	local dt = 10
	gui.animate(self.blue_fills[1], gui.PROP_POSITION, vmath.vector3(qwe.x, qwe.y + 20, qwe.z), gui.EASING_INOUTSINE, dt, 0, function()
		local qwer = gui.get_position(self.blue_fills[1])
		pprint(qwer)
	end)
end

PS. I added the local keyword in front of some of your variable declarations. If you don’t the variables will become global and it can result in unwanted side effects.

3 Likes

I understood. Its a really useful thing. Thank you very much!

1 Like