Currently to find my rank you have to go through this huge line of if statements, I was wondering if there a solution that could shrink this down in to just one pass, so instead of str, end, dex, ect.. being passed through in a bunch of if's, instead the a list called rank with a all the attributes going through and displaying the rank.
[Range (0, 999)]
public int strength;
[Range (0, 999)]
public int endurance;
[Range (0, 999)]
public int dexterity;
[Range (0, 999)]
public int agility;
public int strengthRank;
public int enduranceRank;
public int dexterityRank;
public int agilityRank;
void Update () {
Rank ();
}
void Rank () {
strengthRank = (strength >= 0 && strength <= 99) ? 0 :
(strength >= 100 && strength <= 199) ? 1 :
(strength >= 200 && strength <= 299) ? 2 :
(strength >= 300 && strength <= 399) ? 3 :
(strength >= 400 && strength <= 499) ? 4 :
(strength >= 500 && strength <= 599) ? 5 :
(strength >= 600 && strength <= 699) ? 6 :
(strength >= 700 && strength <= 799) ? 7 :
(strength >= 800 && strength <= 899) ? 8 :
(strength >= 900 && strength <= 999) ? 9 : 0;
enduranceRank = (endurance >= 0 && endurance <= 99) ? 0 :
(endurance >= 100 && endurance <= 199) ? 1 :
(endurance >= 200 && endurance <= 299) ? 2 :
(endurance >= 300 && endurance <= 399) ? 3 :
(endurance >= 400 && endurance <= 499) ? 4 :
(endurance >= 500 && endurance <= 599) ? 5 :
(endurance >= 600 && endurance <= 699) ? 6 :
(endurance >= 700 && endurance <= 799) ? 7 :
(endurance >= 800 && endurance <= 899) ? 8 :
(endurance >= 900 && endurance <= 999) ? 9 : 0;
dexterityRank = (dexterity >= 0 && dexterity <= 99) ? 0 :
(dexterity >= 100 && dexterity <= 199) ? 1 :
(dexterity >= 200 && dexterity <= 299) ? 2 :
(dexterity >= 300 && dexterity <= 399) ? 3 :
(dexterity >= 400 && dexterity <= 499) ? 4 :
(dexterity >= 500 && dexterity <= 599) ? 5 :
(dexterity >= 600 && dexterity <= 699) ? 6 :
(dexterity >= 700 && dexterity <= 799) ? 7 :
(dexterity >= 800 && dexterity <= 899) ? 8 :
(dexterity >= 900 && dexterity <= 999) ? 9 : 0;
agilityRank = (agility >= 0 && agility <= 99) ? 0 :
(agility >= 100 && agility <= 199) ? 1 :
(agility >= 200 && agility <= 299) ? 2 :
(agility >= 300 && agility <= 399) ? 3 :
(agility >= 400 && agility <= 499) ? 4 :
(agility >= 500 && agility <= 599) ? 5 :
(agility >= 600 && agility <= 699) ? 6 :
(agility >= 700 && agility <= 799) ? 7 :
(agility >= 800 && agility <= 899) ? 8 :
(agility >= 900 && agility <= 999) ? 9 : 0;
I'm wondering if I could get it to something like this
[Range (0, 999)]
public int strength;
[Range (0, 999)]
public int endurance;
[Range (0, 999)]
public int dexterity;
[Range (0, 999)]
public int agility;
public int rank;
void Update () {
Rank ();
}
void Rank () {
rank = (x >= 0 && x <= 99) ? 0 :
(x >= 100 && x <= 199) ? 1 :
(x >= 200 && x <= 299) ? 2 :
(x >= 300 && x <= 399) ? 3 :
(x >= 400 && x <= 499) ? 4 :
(x >= 500 && x <= 599) ? 5 :
(x >= 600 && x <= 699) ? 6 :
(x >= 700 && x <= 799) ? 7 :
(x >= 800 && x <= 899) ? 8 :
(x >= 900 && x <= 999) ? 9 : 0;