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

0 favourites
  • 10 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • 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.

  • 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

  • Do you mean this? The main interest is the "DoIt" function. The rest is candy

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

    Thx

  • Sure here's the whole thing.

  • 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.

  • Hei,

    does this help

    [attachment=0:ftxnny88][/attachment:ftxnny88]

    Beni

  • Hi beni92,

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

    Thanks.

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

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