Why does this happen?

Discussion and feedback on Construct 2

Post » Sat Apr 16, 2016 10:24 am

Hello, I do not understand what is happening here, why the X coordinate of sprite is not positioned ?.

The X coordinate is always 0, never is 50 or 100 or 150 or 200.

https://dl.dropboxusercontent.com/u/60803633/test2.capx

Someone could take a look?
B
29
S
12
G
20
Posts: 756
Reputation: 13,855

Post » Sat Apr 16, 2016 10:41 am

I dont think that event system works in 'on start of layout'.

Do it simple. Set X to choose(100,150,200,250) in the creation action.
B
33
S
18
G
27
Posts: 2,436
Reputation: 20,336

Post » Sat Apr 16, 2016 10:46 am

working
Image


edit:
or add sub-event
Image
Last edited by Eren on Sat Apr 16, 2016 11:02 am, edited 2 times in total.
B
34
S
18
G
14
Posts: 17
Reputation: 9,046

Post » Sat Apr 16, 2016 10:52 am

But I do not understand, why this is so ?.
B
29
S
12
G
20
Posts: 756
Reputation: 13,855

Post » Sat Apr 16, 2016 11:03 am

Well, am not 100% sure, but. I think that a newly created instance actualy gets created in the next tick.

You can apply actions to a newly created instance, right after a "Create" action, but you can't do picking of that instance before the next event.

But the 'on start of layout' does not execute in the next tick. This makes the pick events beeing skipped.

There is a simple trick to know if your 'on start of layout' has a problem with picking. And that happens a lot if you are not carefull. Change the 'on start of layout' to 'on mouse clicked'. If it works now, you need to bring the events out of the 'on start of layout'.
B
33
S
18
G
27
Posts: 2,436
Reputation: 20,336

Post » Sat Apr 16, 2016 11:11 am

99Instances2Go wrote:Well, am not 100% sure, but. I think that a newly created instance actualy gets created in the next tick.

You can apply actions to a newly created instance, right after a "Create" action, but you can't do picking of that instance before the next event.

But the 'on start of layout' does not execute in the next tick. This makes the pick events beeing skipped.

There is a simple trick to know if your 'on start of layout' has a problem with picking. And that happens a lot if you are not carefull. Change the 'on start of layout' to 'on mouse clicked'. If it works now, you need to bring the events out of the 'on start of layout'.



That makes sense, thanks to everyone !.
B
29
S
12
G
20
Posts: 756
Reputation: 13,855

Post » Sat Apr 16, 2016 7:27 pm

The newly created objects are not pickable outside of sub-events till the next toplevel event.
More info here:
viewtopic.php?f=147&t=152869&p=964496&hilit=toplevel#p964496
B
91
S
31
G
102
Posts: 5,233
Reputation: 67,252

Post » Sun Apr 17, 2016 9:32 am

R0J0hound wrote:The newly created objects are not pickable outside of sub-events till the next toplevel event.
More info here:
viewtopic.php?f=147&t=152869&p=964496&hilit=toplevel#p964496


Ok thanks for the info, I think it is quite clear.
B
29
S
12
G
20
Posts: 756
Reputation: 13,855

Post » Sun Apr 17, 2016 10:12 am

Mirlas wrote:
R0J0hound wrote:The newly created objects are not pickable outside of sub-events till the next toplevel event.
More info here:
viewtopic.php?f=147&t=152869&p=964496&hilit=toplevel#p964496


Ok thanks for the info, I think it is quite clear.



in order for the var condition to be working on your sprite i suggest add it on the sprite as a instance variable instead of a global variable. the way you made the events... you created a sprite object and thats it.
then added 2 conditions that triggers the actions for positioning the sprite that is referring to all the sprite objects existing on the map not to 1 or the new just created.
you need to identify the sprite you just created in order to move that one only.

for example i do a "type" instance variable usually then when a sprite is created i add the type number to the count of sprites existing that way i can say if C= sprite.type=5 set - A= sprite.setx to N
B
70
S
20
G
67
Posts: 1,314
Reputation: 42,301


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests