Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Sorting variables.

Status
Not open for further replies.
Excuse my bad english
Hello guys. Can you help me with something? I'm working on an evented tactical battle project and I need for the battle order a way to sort variables . Lets say that I have 5 variables named ABCD& E. Can I sort them so that the value of the highest variable is change to 1? For example if C is the highest among all its value is change to 1 ; if E is the second, its value is change to 2 etc ( actually I have 12 variables to sort but if I'm told how to do it with 5...)
Thank you guys.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Hmmm sounds like a good challenge, I'm not 100% sure how I would go about doing this but it sounds possible to do, you may need a bit of javascript to accomplish it. Let me play around a bit on MV and I'll see what I can do. I'll report back, I am a bit busy right now so don't expect me back too soon lol.
 

Mr. Trivel

Praised Adventurer
Xy$
0.00
So, to turn something like this:


Into such values?:


If yes, I used this script call:
JavaScript:
var arr = [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18];
arr.sort(function(a, b) {
   return $gameVariables.value(b) - $gameVariables.value(a);
});
for (var i = 0; i < arr.length; i++) {
  $gameVariables.setValue(arr[i], i+1);
};
 
Thank you for replying so fast. You solve my problem plus I got to learn some usefuls things such as setup an array. Thank you both for your help.
 

Xyphien

Owner
Staff member
Administrator
Resource Team
Xy$
9.57
Thank you for replying so fast. You solve my problem plus I got to learn some usefuls things such as setup an array. Thank you both for your help.
Make sure you mark the answer that solved your problem with "Best Answer" it's next to the Reply button.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I'm closing thread due to being addressed & solved if for any reason you would like it re-opened please report the post.
 
Status
Not open for further replies.
Top