# How do I compare two values between each other?

Get help using Construct 2

### » Tue Nov 08, 2016 8:49 am

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.
B
29
S
12
G
1
Posts: 166
Reputation: 3,011

### » Tue Nov 08, 2016 8:58 am

System > General > Is between values
B
49
S
20
G
89
Posts: 2,341
Reputation: 52,693

### » Tue Nov 08, 2016 9:06 am

Can you please explain how I can convert my earlier method using this?
B
29
S
12
G
1
Posts: 166
Reputation: 3,011

### » Tue Nov 08, 2016 9:11 am

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.
B
29
S
12
G
1
Posts: 166
Reputation: 3,011

### » Tue Nov 08, 2016 9:13 am

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).
B
49
S
20
G
89
Posts: 2,341
Reputation: 52,693

### » Tue Nov 08, 2016 9:22 am

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?
B
29
S
12
G
1
Posts: 166
Reputation: 3,011

### » Tue Nov 08, 2016 9:30 am

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.
B
49
S
20
G
89
Posts: 2,341
Reputation: 52,693

### » Tue Nov 08, 2016 9:36 am

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%)
B
29
S
12
G
1
Posts: 166
Reputation: 3,011

### » Tue Nov 08, 2016 9:39 am

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!
B
29
S
12
G
1
Posts: 166
Reputation: 3,011