How do I select only the instance that was just spawned?

Get help using Construct 2

Post » Thu Jun 16, 2016 11:06 pm

Event Triggered
-Spawn Bullet
-Set Bullet direction

Most of the time only the recently spawned bullet will be affected.

But I have seen several times where all bullets on the screen change direction to move in the same direction as the new bullet.

I don't have an isolated example but I don't believe I have any other events that affect bullet direction.

Do I need to set this up differently?

Thanks
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Thu Jun 16, 2016 11:14 pm

Would Z order pick ("pick top/bottom") work in your case? Pick the sprite on top?
B
32
S
9
G
4
Posts: 133
Reputation: 4,350

Post » Thu Jun 16, 2016 11:31 pm

That shouldn't happen. The spawned item would be the most recently picked. If the subsequent actions are at the same level or lower, it should work. You'd have to show a solid example for further help.
ImageImageImage
B
71
S
21
G
231
Posts: 3,695
Reputation: 129,366

Post » Fri Jun 17, 2016 12:16 am

Try using the "Pick instance by UID" condition, the value being "[sprite].count -1". This should select the newest instance. You could also try comparing the distance to the player & picking the instance w/ the lowest distance.
B
7
S
2
Posts: 14
Reputation: 512

Post » Sat Jun 18, 2016 1:19 pm

blackhornet wrote:That shouldn't happen. The spawned item would be the most recently picked. If the subsequent actions are at the same level or lower, it should work. You'd have to show a solid example for further help.


That's what I thought as well. I have just changed the only other events that could be the cause and am going to retest. Problem was it was happening rarely so might take a while to see if it happens again.

If it is still happening I might look at using the "on created" trigger.
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Sat Jun 18, 2016 1:23 pm

This part I haven't changed:

Image
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Sat Jun 18, 2016 4:30 pm

I have a lot of instances of the same object in my current project. I assign an instance variable to the latest created - and a global variable to match the latest created object.

When an instance of a particular object is created, I use an instance variable (called ActorID) that is set to the current "actor.count" as well as the global variable.

Maybe something like this will help?
Variables are awesome...

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Sun Jun 19, 2016 2:31 pm

SoldjahBoy wrote:I have a lot of instances of the same object in my current project. I assign an instance variable to the latest created - and a global variable to match the latest created object.

When an instance of a particular object is created, I use an instance variable (called ActorID) that is set to the current "actor.count" as well as the global variable.

Maybe something like this will help?
Variables are awesome...

~Sol


I agree. Variables are definitely the concrete solution if needing to track something and worry about picking which instance.

For this issue it is a bullet basically, so set it and forget it. No tracking needed.

I think I figured it out—this post was kind of a process of elimination line of thinking to rule out this as the problem.

Thank you for the comment—I will probably end up using that idea in a future scenario.
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Post » Mon Jun 20, 2016 2:06 am

No worries! :D

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Tue Jun 21, 2016 1:09 pm

SoldjahBoy wrote:No worries! :D

~Sol


Actually, it is still doing it but I think I figured out why.

This is basically what I have

On timer
--animate
-- Wait short time (0.3 seconds or so)
-- Monster spawn bullet object
-- Set bullet direction

I actually thought this through while away from project and testing but I think this is why it is happening:

If the monster is hit/damaged and destroyed between the timer going off and the spawning (so 0.3 seconds time window) there is no new bullet spawned. Only one monster is picked and it is destroyed so no monster is left picked to spawn a bullet. And since no bullet is spawned then setting the bullet direction will pick ALL of the bullets.

So I was thinking of changing it to:
-- Monster spawn bullet object
-- Set instance variable (to the angle)

On bullet created
--Set direction to instance variable

So even if monster is destroyed and all bullets are picked it will just set an instance variable that won't be used again.

Will the On bullet created fire before the instance variable is set though? Should I put a miniscule wait in there? How small? 0.05 seconds?

Or can anyone think of a better solution?
ImageImageImage
B
39
S
22
G
11
Posts: 492
Reputation: 9,925

Next

Return to How do I....?

Who is online

Users browsing this forum: MadSpy and 58 guests