How do I ... do instanceOf

Get help using Construct 2

Post » Sun Aug 02, 2015 12:07 pm

Is it possible within families to detect what the base type is ?

Suppose I have two objects enemyA and enemyB and their movement is handled by being in a family 'enemy'. I want these two enemies to run at different speeds, but the bullet behaviour that defines the movement is part of the family. From the base type (enemyA/enemyB) you can't access the family supertype, and from the supertype there doesn't seem to be an easy way to identify the base type (e.g. is it enemyA or enemyB)

So in the on enemy create, I want to set the speed, but I need to know whether the enemy is of type "enemyA" or "enemyB".

I have managed to sort of make it work because objects only have one UID, whether they are in a family or not, so I can do pick by uniqueID enemyB where UID is enemy.UID and that picks up an object that is type enemyB.

e.g.
Pick by UniqueID enemyA where enemyA = enemy.UID : Set enemyA.bulletSpeed to 32
Pick by UniqueID enemyB where enemyB = enemy.UID : Set enemyB.bulletSpeed to 32

appears to work but is there a better way of doing this ?

Can this be relied on in the run time - that objects have one UID only and that if they are in 10 different familes, the UID in that family will be the same as the UID in the base type ?
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328

Post » Sun Aug 02, 2015 12:12 pm

Wouldn't it be easier to do something like this?

enemyA on created
> set bullet speed

enemyB on created
> set bullet speed
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Aug 02, 2015 12:40 pm

Yes .... my bad. I was trying to do it from another family (which doesn't work), but if you use the base object you can access the superclass - thanks for that :)
My tutorial through development blog is at http://myconstruct2dev.blogspot.co.uk/
B
12
S
3
Posts: 221
Reputation: 1,328


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests