How to spawn an object from another object that spawns?

Get help using Construct 2

Post » Sun Oct 30, 2016 12:17 am

Image

The alldisks are created every random (1, 2) secs above and below the viewport and move at 90 or 180 degrees. . As you can see from the image, a starblue is spawned for every alldisk that is created. All that works correctly.

For each starblue that is destroyed 1 is added to a globalvariable named StarBluecount.

I'm trying to get it so that when random(50, 100) starblue is destroyed, it, or an a alldisks spawns a single stargold.

I've tried using variations of event/actions to get the starblue or the alldisks to spawn the object, but no luck. The starblue will either not spawn anything or spawn a stargold for each starblue that is created. And the alldisks will either spawn all blue or gold.

Been working on this for about 6 hours now, and the posts/ tutorials aren't close to what i need to do. If anyone can school me, it would be greatly appreciated.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Sun Oct 30, 2016 4:52 am

Not real clear on what's happening, or how you are going about it. Are you jumping to a function, which loses which starblue is picked?
Or you don't spawn until after the event, which also loses the picked Starblue?
B
226
S
60
G
33
Posts: 902
Reputation: 39,989

Post » Sun Oct 30, 2016 7:35 am

How about you try separate event instead of the sub-event ?
B
11
S
2
G
1
Posts: 34
Reputation: 722

Post » Sun Oct 30, 2016 12:56 pm

@kaveljo @Paradox Thanks for the replies. Let me try to explain a bit better.

I have 6 disks in the AllDisks Family --

Small, Medium, Large that have bullet behavior and move with - bullet angle of motion 90 degrees. They are created out of sight just above the viewport every random(1,2)secs and move from top to bottom, where they are destroyed outside of layout.

Small, Medium, Large that have bullet behavior and move with - bullet angle of motion 180 degrees. They are created out of sight just below the viewport every random(1,2)secs and move from bottom to top, where they are destroyed outside of layout.

Each separate disk has its own event/action, since they each move at their own random speed, and are created at different intervals, as seen in the example image.

Image



For each AllDisks that is created, it spawns a single StarBlue.

The user has to roll a ball around over the disks without falling off the edges and collect as many of the StarBlue as they can. On collision with the ball, each StarBlue is destroyed and counted.

I'm trying to make it so that when the user has collected/destroyed a random number of StarBlue, a single StarGold is created/spawned on just 1 random AllDisks.

For example: StarCount is equal/ greater than 100 > System choose(a random disk from the AllDisk family) - spawn 1 StarGold -- StarGold pin to the AllDisk that was created at image point 0.

Or something like that. So, basically i need 1 StarGold to be created when the user has collected between 50-100 StarBlue. And have that StarGold be pinned to a random disk.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Sun Oct 30, 2016 1:43 pm

Hi @jeffige!

Maybe you should try using the Pick nth instance condition from System, with expression random. Something like :
StarCount is equal/ greater than 100 AND Pick AllDisks instance (random(0, AllDisks.Count -1)) --> Spawn StarGold on AllDisks; Pin; etc...
Image
B
10
S
3
G
2
Posts: 75
Reputation: 1,708

Post » Sun Oct 30, 2016 2:10 pm

@Bro7hers Thanks for the reply

I have no experience with the Nth instance expression, but i'll check it out.



Again, thanks for the reply.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Sun Oct 30, 2016 2:37 pm

You're welcome, tell me if it worked out!
Image
B
10
S
3
G
2
Posts: 75
Reputation: 1,708

Post » Wed Nov 02, 2016 4:01 pm

@Bro7hers thanks for the help, but i decided that adding the Gold star was a bit too much and detracted from the gameplay.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Fri Nov 04, 2016 9:30 am

No problem! Looking forward to see the game. :)
Image
B
10
S
3
G
2
Posts: 75
Reputation: 1,708

Post » Fri Nov 04, 2016 10:15 am

Can't see the image of the issue, it seems to be down for now, or has been removed, nonetheless from the description it could be an issue with
Understand the picking of newly created/spawn instances since R101 - LINK


The same delay applies to destroying instances as well, and picking a newly created instance in a sub-event just does not allow to pick it as the instance does not exists at the moment of the execution of the sub-event.
A solution is to have the system action "Wait 0 second" that will skip a frame and execute the next action. And the next action should be a call to a function that picks the UID of the newly created instance (this UID exists in the current event) and actually the function is made of the actions of the sub-event.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,319
Reputation: 87,487


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests