How do I select a specific instance variable for a sprite?

  • i have a sprite representing the player, it has four instance variables...

    forward, right, back, left;

    each of the above variables has a certain amount of HP value associated with;

    What i'm trying to do is have the AI pick the instance variable based on the HP value, i.e.

    if AI_sprite within some range of PC_sprite

    evaluate the four instance variables

    and pick the one with the lowest value

    then move AI_sprite to the position represented by

    the Instance variable

    I can do it if i have a separate 4x4 array with HP value on the X axis and the positions on the Y axis, then sort by HP value, however, i have a feeling there should be a simpler way of evaluating instance variables associated with a single object.

    Thanks

  • min(player.forward, player.right, player.back, player.left)
    

    and if you have those instant variables on an npc you can loop through them with a For Each.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • thanks for the reply,

    unfortunately, using the min() method only gets you the value of the lowest instance variable;

    i guess i should have been more clear, i'm more interested in knowing which variable is the one with the lowest value;

    aside from using an array, i could do 4 actions iterated by an else statement, something like the following:

    if forward < min(player.forward, player.right, player.back, player.left)

    do this;

    else right < min(player.forward, player.right, player.back, player.left)

    do this;

    else back < min(player.forward, player.right, player.back, player.left)

    do this;

    else left < min(player.forward, player.right, player.back, player.left)

    do this

  • you could do that, but seems like you could somehow store the direction, so you don't have to check what it actually is.

    you could have a an invisible sprite with 4 instantances that represent the health bars, give them an hp variable and set them up in their perspective angles. Then pick based on lowest hp and then take that one's direction/angle.

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