How do I make a objects instance variable depend on anothers

0 favourites
  • 3 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm trying to make AI for an enemy and i want to make them run to where they last saw the enemy. To do this, i made a sprite that would spawn when the enemy sees the player. The problem is, how does the game know which enemy has seen the player. To fix this I made an instance variable for the enemy and the sprite that last saw you. I then made the enemy have a random number and tried to make the object that follows the player that same value but i cant get the object that follows the player's instance variable to be dependent on the enemy's instance variable. Please Help .

  • I call this the "Mate" variable (literally I do, but it isn't its technical term).

    I'll try explain it:

    When you create the sprite which is associated with the player or the enemy, assign a variable in itself to the UID of the object it is associated (or tracking in your case) with. Then when you want to conditional or action against it, pick the Object by UID against the "Mate" variable.

    If this doesn't make sense let me know and I'll try get a capx or screenshots sorted.

    Keep in mind using IID for references in enemies and sprites can cause issues because if an enemy or sprite is destroyed, the IID for the next enemy/sprite can conflict

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You may also want to pick the instance by the "instanceName" which can be a generated text. I have explained that here scirra.com/forum/how-to-quot-construct-quot-an-object-name-using-variables_t152556

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