Object Creation and On Layout Start

Discussion and feedback on Construct 2

Post » Sat Dec 22, 2012 5:19 pm

I have created two functions (thank you for making functions possible!)

initDeck() and shuffleDeck()

in the event "On Layout Start", I call initDeck() which creates the physical cards on screen. This works no problem.

After that is called, the shuffleDeck() function is called (still within the On Layout Start event).

shuffleDeck is not able to pick created objects for events (ie: DeckOfCards) and therefore does not shuffle the cards.

My shuffle function works as expected, if I place the call within a mouse event (ie: middle button clicked), but not if I call it within "On Layout Start" right after the objects have been created.
B
16
S
5
G
2
Posts: 25
Reputation: 2,784

Post » Sat Dec 22, 2012 5:53 pm

Both functions are running on the same tick, that's why. I believe if you add a "wait 0.01 seconds" between the two function calls you will solve the problem
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,159

Post » Sun Dec 23, 2012 3:46 am

There was somekind of change a number of iterations ago that newly created objects can't be manipulated in the same tick. I'm not sure how entirely true this is as I have managed to with immediately created objects, but it should be considered when doing design work.
B
88
S
18
G
9
Posts: 2,455
Reputation: 14,928

Post » Sun Dec 23, 2012 4:09 am

@jayderyu: The change you're talking about is that the instance is not actually created before the next event of the same level.
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.

That's what happens with the second function.Kyatric2012-12-23 04:10:33
New to Construct ? Where to start



Image Image

Image Image



Please attach a capx to any help request or bug report !
Moderator
B
262
S
93
G
55
Posts: 7,146
Reputation: 67,061

Post » Sun Dec 23, 2012 4:26 am

Well that nicely explains it :)
B
88
S
18
G
9
Posts: 2,455
Reputation: 14,928

Post » Sun Dec 23, 2012 1:20 pm

Thanks everyone...that explains it and gave me a good solution that works. I appreciate a community that is friendly and helpful. Eventually I will have a better understanding of this tool and can return the favor to new users
B
16
S
5
G
2
Posts: 25
Reputation: 2,784


Return to Construct 2 General

Who is online

Users browsing this forum: Whack and 4 guests