Equation to a custon slider

Discussion and feedback on Construct 2

Post » Mon Aug 22, 2016 1:18 pm

I'm making a custum slider.
I have two numbers...

Min = 120
Max = 400

I want:
120 = 0%
400 = 100%

I don't know the equation for this.
I want create a percentage to a custom range... How do i do it?
B
14
S
6
G
2
Posts: 81
Reputation: 2,241

Post » Mon Aug 22, 2016 1:28 pm

Subtract 120, so the range is 0 to 280. 280 is your divisor, so the coordinate X, minus 120 divided by 280 is the factor (0 to 1). Or, the factor multiplied by 280 plus 120 gives you X. (Remember, you don't actually work in percentages. You want a factor from 0 to 1, where the percentage is just the factor times 100).
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Mon Aug 22, 2016 1:31 pm

blackhornet wrote:Subtract 120, so the range is 0 to 280. 280 is your divisor, so the coordinate X, minus 120 divided by 280 is the factor (0 to 1). Or, the factor multiplied by 280 plus 120 gives you X. (Remember, you don't actually work in percentages. You want a factor from 0 to 1, where the percentage is just the factor times 100).


Humm cool. i will use, but when i want:

-100 = 0%
0 = 100%

what do i do?
B
14
S
6
G
2
Posts: 81
Reputation: 2,241

Post » Mon Aug 22, 2016 1:41 pm

You always want a number between 0 and 1, and 0 to be the starting point, so add 100. That gives you 0 to 100. Divide by 100 to get the factor (0to1). Do your math, multiply by 100, then subtract 100 again, to move everything back into range.
ImageImageImage
B
71
S
22
G
241
Posts: 3,734
Reputation: 134,494

Post » Tue Aug 23, 2016 8:53 am

woah what complications, how about this:

x = Min + (random() * ((Max - Min) + 1))

1st problem = minimum is 280, maximum 420.
same thing applies to the 2nd problem, your minimum is -100, while your maximum is 0.
same formula applies. - gives you a random number between your max and min, now if you want percentage of that number in your range you just apply this:

perc = (x /(max+min))*100
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
43
S
14
G
12
Posts: 626
Reputation: 9,450

Post » Tue Aug 23, 2016 6:45 pm

blackhornet wrote:You always want a number between 0 and 1, and 0 to be the starting point, so add 100. That gives you 0 to 100. Divide by 100 to get the factor (0to1). Do your math, multiply by 100, then subtract 100 again, to move everything back into range.


Thanks
B
14
S
6
G
2
Posts: 81
Reputation: 2,241

Post » Tue Aug 23, 2016 6:45 pm

saiyadjin wrote:woah what complications, how about this:

x = Min + (random() * ((Max - Min) + 1))

1st problem = minimum is 280, maximum 420.
same thing applies to the 2nd problem, your minimum is -100, while your maximum is 0.
same formula applies. - gives you a random number between your max and min, now if you want percentage of that number in your range you just apply this:

perc = (x /(max+min))*100


Hey, perfect! Thank you!
B
14
S
6
G
2
Posts: 81
Reputation: 2,241


Return to Construct 2 General

Who is online

Users browsing this forum: JesusJ and 31 guests