Relations between instances

Get help using Construct 2

Post » Mon Mar 24, 2014 12:37 pm

Hi, how can I create link between two instances ? In normal programming you can do this by setting "instance variable" on an object and then assign another object to this variable, but in construct it seems that only 3 basic types are allowed for instance variable: string, number and boolean.


I would like to make connection between two objects, because I have tower (with turret behaviour) that shots bulets. Now when bullet hits enemy, i have no way to get somehow tower that has shot that bullet, but i need to get this tower because I want to increase experiance for it.

Only way I see to do so is to put number variable on bullet, pass UID to that var while creating bullet and then add condition pick tower where tower.UID = bullet.tower_UID on the bullets with enemy collision event.

Is there better aproach for such thing ?
B
4
Posts: 8
Reputation: 216

Post » Mon Mar 24, 2014 3:26 pm

fishol wrote:Hi, how can I create link between two instances ? In normal programming you can do this by setting "instance variable" on an object and then assign another object to this variable, but in construct it seems that only 3 basic types are allowed for instance variable: string, number and boolean.


I would like to make connection between two objects, because I have tower (with turret behaviour) that shots bulets. Now when bullet hits enemy, i have no way to get somehow tower that has shot that bullet, but i need to get this tower because I want to increase experiance for it.

Only way I see to do so is to put number variable on bullet, pass UID to that var while creating bullet and then add condition pick tower where tower.UID = bullet.tower_UID on the bullets with enemy collision event.

Is there better aproach for such thing ?


Have an instance variable for your bullet (a number) called TowerID
When you create your bullet, set it's variable to the unique Id of the tower that spawned it (Tower.UID if Tower is the name of the tower)

Then you can later do :

Bullet on collision with Ennemy:
Pick Tower by UID TowerID : add experience
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Wed Dec 24, 2014 6:36 pm

i was just about to submit a question like that, and the solution was amazing, thx a lot!
B
7
S
1
Posts: 28
Reputation: 481


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 35 guests