How do I pick the highest instance from a var in a family

Get help using Construct 2

Post » Tue Dec 09, 2014 7:45 am

I have 3 sprites, one and two are in a family with 1 variable "aggro"

Third sprite is in no family with variables tarX, tarY

The script runs:
for each "third sprite" > check for family member instance with the highest agro third sprite > set tarX to family.X

My issue is no matter the aggro var I set to sprites it always returns instances of the first sprite, never seems to check the second sprite.

Sorry for only text as i'm out and about, I will post an image in a few hours.

Thanks.
B
4
Posts: 4
Reputation: 208

Post » Tue Dec 09, 2014 10:05 am

Hei,

you could go thru all members of the family and save the highest value and the UID from the instance in a variable.

something like that:

function getHighestVar
{
local var1
local var2
foreach fam
{
if(var1 < fam.var)
{
var1 = fam.var
var2 = fam.UID
}
}
return var2
}

and then you go like pick by uid with calling the function

i hope i could help
B
5
Posts: 27
Reputation: 277

Post » Tue Dec 09, 2014 10:52 am

Do you mean this? The main interest is the "DoIt" function. The rest is candy :)
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Dec 09, 2014 11:10 am

I can't open this right now, can you make a screenshot from the parts and post it please

Thx
B
5
Posts: 27
Reputation: 277

Post » Tue Dec 09, 2014 11:19 am

Sure here's the whole thing.
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Dec 09, 2014 11:44 am

Thx for the replies all.

The code I was trying to get to work can be seen in attachments. The gist of what i'm trying to do is that every so often the enemy sprites will check to see who has the highest agro and update their tarX,Y variables. I cannot seem to get the event to return ether a hero or gate so that the enemy can update its variables.

This is not what I think my final code will be, instead of tarX,Y it will be tarUID but have not tried this until I get this running.

Thank you.
You do not have the required permissions to view the files attached to this post.
B
4
Posts: 4
Reputation: 208

Post » Tue Dec 09, 2014 11:51 am

Hei,

does this help

function.capx


Beni
You do not have the required permissions to view the files attached to this post.
B
5
Posts: 27
Reputation: 277

Post » Tue Dec 09, 2014 12:18 pm

Hi beni92,

That works great, I was planning on putting it into a function call as well.

Thanks.
B
4
Posts: 4
Reputation: 208

Post » Tue Dec 09, 2014 12:26 pm

BlackYama wrote:Thx for the replies all.

The code I was trying to get to work can be seen in attachments. The gist of what i'm trying to do is that every so often the enemy sprites will check to see who has the highest agro and update their tarX,Y variables. I cannot seem to get the event to return ether a hero or gate so that the enemy can update its variables.

This is not what I think my final code will be, instead of tarX,Y it will be tarUID but have not tried this until I get this running.

Thank you.


Isn't that what I did, but I did it in a function? Anyway good you got a solution.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Dec 10, 2014 4:42 am

codah wrote:Isn't that what I did, but I did it in a function? Anyway good you got a solution.



Hi Codah,

Yea, both are right and also mine, was not a problem with my code but the fact that I had two families, first with both gate and hero inside and a second with hero alone. This seemed to be enough to break the event but still not sure how.

Thanks everyone for helping.
B
4
Posts: 4
Reputation: 208


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 12 guests