How do I ... do instanceOf

0 favourites
  • 3 posts
  • 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.


    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 ?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Wouldn't it be easier to do something like this?

    enemyA on created

    set bullet speed

    enemyB on created

    set bullet speed

  • 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

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