How do I compare a Variable between instances of an Object

Get help using Construct 2

Post » Tue Oct 13, 2015 10:42 am

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.
B
3
Posts: 3
Reputation: 181

Post » Tue Oct 13, 2015 5:32 pm

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.
B
45
S
21
G
65
Posts: 1,115
Reputation: 38,221

Post » Fri Oct 16, 2015 6:35 pm

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.
B
3
Posts: 3
Reputation: 181

Post » Fri Oct 16, 2015 6:45 pm

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
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,718

Post » Sun Oct 18, 2015 3:49 pm

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!
B
3
Posts: 3
Reputation: 181


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot] and 49 guests