How do I ensure my code is being reused for each instance?

1 favourites
  • 3 posts
From the Asset Store
5 levels with simple coding Source-code (.c3p) + HTML5 Exported
  • Hi there! This is my first time posting here, but I'm really confused and could use some help:

    My code is a Tower Defense style game where enemies come through and are shot by the player placing troops. I was trying to ensure that the troops hit their target each time, but everything I try only seems to apply to one troop. The problem is that the opponents are clones of one sprite, so I have to use UID's to figure out which one to track. I thought I figured it out, but for some reason the code only applies to the first troop I place?

    Here is the code that I am using; I think it's the only code that affects bullet direction, but I will also include my .C3p to be sure.

    BsicTroop.UIDbullet is the bullet's UID, given to the Basic troop it was fired from.

    BsicTroop.Turret.TargetUID is the UID of the target the turret is aiming at.

    ENemies is a group of all of my Enemies including my basic enemy.

    :( Like I said, this method seems to work for the first one I place, but not for the second, which simply uses the turret's angle to shoot, which doesn't work since the bullet is coming from an img point.

    My file: 1drv.ms/u/s!AhvNCTqQh6yBjksNn5Oiolms3vSR

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Edit: Regarding this code, I think the answer lies somewhere in the shift from the firs to the second block: Maybe it doesn't get the right bsicTroop UID after the first one? Any Ideas?

  • Nvm I figured it out: For anyone curious the instance variable was set to a sprite with multiple occurrences and so I had to make it a sub event to correctly implement it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)