Quick way to test the difference between 2 values

0 favourites
  • 8 posts
From the Asset Store
Soldier Test
$9.99 USD
A Construct version 2 & 3 "Stand-alone" RPG game with "In-Game Module" (IGM) integration.
  • Is there an easy way to just test the difference between 2 values? I'm making my own directional animation events which should say something like:

    If (Sprite.X < Destination.X)

    and (difference (Sprite.Y,Destination.Y) < difference (Sprite.X,Destination.X))

    Set animation "WalkRight"

    If (Sprite.Y < Destination.Y)

    and (difference (Sprite.Y,Destination.Y) > difference (Sprite.X,Destination.X))

    Set animation "WalkDown"

    ... and so on for all the other directions. I know I can do it manually by subtracting one value from another, but all the Cartesian positive/negative stuff's twisting my head a bit Is there an easier way to do what I'm trying to do?

  • You can use abs() to get rid of the sign,

    https://www.scirra.com/manual/126/system-expressions

  • Nice - that works, but I still seem to need 8 events rather than 4. Eg for "WalkRight", I need to test twice - one for when Sprite.Y > Destination.Y, and one for when Sprite.Y < Destination.Y, as it changes the order of the subtractions. Might be my crappy logic though! Is there a way to do it in 4 nice neat events?

  • You can have 2 events with 2 subevents each. Events will calculate the difference (first will do it for X, second for Y) and subevents will look for relative position.

  • That's a lot neater, but still not sure I've got it. Here's the problem I'm having:

    The Up and Left directions work fine all the time, Down and Right only work sometimes. Pretty sure know why it isn't working - half the time the wrong absolute value is being subtracted, it should always be the smaller one subtracted from the greater one. I just can't figure out a (simple) way to do it.

    If I could just replace the values in those abs events with with "difference (EnemyZombie.X,EnemyZombieDetector.X)" I'm pretty sure it'd work fine.

  • No, you abs(EnemyZombie.X-EnemyZombieDetector.X) ...

  • BOOM. I'm an idiot thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could use conditionals and just set the animation based on those.

    set animation to:

    x>n ?thisanimation :thatanimation

    Not sure how you would chain multiple conditionals together.

    A nice suggestion for C3 would be easier ways to set stuff like that up.

    I realize the canned answer is just use conditions and subevents, but even those are somewhat broken when you want to use else, and or together.

    Ashley

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