Pass value into a "on created event"/constructor

Get help using Construct 2

Post » Sun Jan 26, 2014 1:56 am

I have three events.

On sprite A created -> create sprite B

On sprite B created -> create sprite C

A, B, and C each has a number "myValue." How do I make sure they all have the same myValue?

There are many instances of A, B, and C. Each set of 3 should have the same myValue.

Thanks!
B
11
S
2
Posts: 68
Reputation: 982

Post » Sun Jan 26, 2014 3:08 am

I just use a global, and set the global before creating the object.
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,744

Post » Sun Jan 26, 2014 4:31 am

Thanks for the reply. Can a global cause a race condition?

For example A1 is created with my value = 1 and A2 is created with my value = 2 at the same time. What should the global be?
B
11
S
2
Posts: 68
Reputation: 982

Post » Sun Jan 26, 2014 4:58 am

Set myValue when creating A, then On Create A->create B, set B.myValue = A.myValue, etc.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Sun Jan 26, 2014 6:08 am

Hi Blackhornet. Unfortunately construct 2 does not work that way. By the time I can set B.myValue, C is already created and it doesn't have access to A.myValue.
B
11
S
2
Posts: 68
Reputation: 982

Post » Sun Jan 26, 2014 6:40 am

set a global "count" value at zero

one event > Add 1 to global count
            create A
            set val to global
            create B
            set val to global
            create C
            set val to global
As long as I can move left, right and fire, I'm Happy...
B
42
S
15
G
11
Posts: 655
Reputation: 12,260

Post » Sun Jan 26, 2014 4:46 pm

On Create B->create C, set C.myValue = B.myValue,
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests