How do I compare a Variable between instances of an Object

0 favourites
  • 5 posts
From the Asset Store
112 High-Quality destruction sounds for videogames
  • Hi, I'm trying to create a big fish eats little fish type scenario, where any instance of the fish object will chase smaller instances of themselves.

    I currently have it working where if a fish is within 100 pixels of another fish it will chase it and that works, however when I add the condition to compare an instance variable i've created called Weight. It seems to be comparing againts itself instead of the other instance of the object which doesn't give me the result i am after.

    I guess what I'm after is how do I get the each fish instance to compare it's own Weight instance variable with the variables of other fish instances within 100 pixles?

    Hope that makes sense.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Put the fish into a family, and compare a fish with the family.. This essentially compares a fish to a fish. You will have to put the instance variable into the family instead of the fish, for the variable to be accessible to both a fish instance and a family instance.

  • Thanks for that info, I'm currently just using the free version so I have to make up my mind if I want to upgrade now. Cheers.

  • Use 1 sprite with each frame being a fish. Put instance variables in sprite of fish.

    Now compare sprite against sprite... works same as family, except restrictive to 1 type of something.

    Now compare fish with fish

  • Sorry I'm a bit confused with what you mean. When you say use 1 sprite with each frame being a fish. Are you talking about animation frames what does this have to do with instance variables?

    Also you say to now compare sprite against sprite then fish against fish, isnt this the same thing?

    Thanks for your help!

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