How do I compare two values between each other?

0 favourites
  • 9 posts
From the Asset Store
Footsteps SFX Two contains 450 sounds of steps and jumps on different surfaces.
  • Instead of using the compare two values event:

    if 'random(100)

    < Less or equal

    50'

    (that's a 50% chance for the event to trigger)

    how can I say

    'random(100)

    <Less or equal

    Between 50 and 70'

    To add context, my way of understanding % in construct is by using Compare two values. The setup I just showed involved the construct 2 engine choosing a random number between 0 and 100, and if the number chosen is below or equal to 50, then the event will trigger, thus 50% chance.

    But, what if I want to have it trigger if the number falls between two specific numbers? Such as the 'Between 50 and 70' example I gave.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • System > General > Is between values

  • Can you please explain how I can convert my earlier method using this?

  • Let me add on to this, I didn't explain very well.

    I have a set of events that change a sprite's animation frame at the beginning of the layout.

    For this, I have set up:

    'For Each Sprite

    ---if 'random(100)

    ---< Less or equal

    ---50

    ------------------------------->Set Animation Frame 0

    ---if 'random(100)

    ---> Greater or equal

    ---51

    ------------------------------->Set Animation Frame 1

    ---if 'random(100)

    ---<Less or equal

    ---3

    ------------------------------->Set Animation Frame 2

    So, that's a 50% chance for 0, 50% chance for 1 and 3% chance for 2.

    Except that equals 103% and makes no sense. So, I need the 1st and 3rd events to be in between two values so the possible outcome of the random(100) number doesn't overlap. I hope that made sense.

  • Using is between values:

    If Value: random(100)

    Lower bound: 50

    Upper bound: 70

    That checks if the randomly generated number is between 50 and 70. So for the first event I guess you need to use this for between 4 and 49.

    The condition works like this : Test if a number is between two values (greater or equal to a lower value and less or equal to a higher value).

  • Okay. Now it's:

    For Each Sprite

    ---- If value random(100) LB: 50 UB: 100 ---> Set frame to 0

    ---- If value random(100) LB: 2 UB: 50 ---> Set frame to 1

    ---- If value random(100) LB: 0 UB: 2 ---> Set frame to 2

    Except, for some reason despite frame 2 having only a 2% chance, it's the one that appears the most. I know it's completely random and there's a chance that it's landed on 0, 1, or 2 for random(100) each time, but that seems unlikely. Any ideas?

  • You've got some conflicting logic there, remember it's greater or equal to lower and less than or equal to higher, so 50 and 2 are true for at least 2 of those scenarios. Youll probs want 50 and 100, 4 and 49, 0 and 3.

  • Alright, I've changed everything to how you said, but frame 2 is still appearing way more often even though it's 0 and 3 now (3%)

  • Scratch that, entirely my fault. I had a different way of randomizing them before and forgot to delete it. Apologies for wasting your time, thank you for your help!

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