hey guys i have a noob question.

i'm trying to program this little text based RPG, i've made several but you're always controlling only 1 character and fighting 1 enemy, i want to change that and make you take control of 4 characters and fight 1-4 enemies at once (turn based)

the problem lies with checking who has the highest speed stat, i want to make an algorithm that selects who has the highest speed, put him in 1st place (attacking first) then who has the 2nd highest speed stat and so on.

i have no idea how to go on about this, please help.

thanks in advance

There are many ways you could go about that. I don't have any algorithm, but one way, Get the speed, go through the other speeds and for each speed its faster than +1 to the priority. Hopefully the example below explains what i'm getting at. So the highest priority goes first.

Player Speed 1: 17 - Faster than 4 others
Player Speed 2: 13 - Faster than 2 others
Player Speed 3: 12 - Faster than 0 others

Enemy Speed 1: 14 - Faster than 3 others
Enemy Speed 2: 12 - Faster than 0 others
Enemy Speed 3: 18 - Faster than 5 others

A simple bubblesort will indeed do the trick here. Also, remember that classes like Array or List have a Sort method.

oh thanks a lot guys, i'll give this a shot.

a few days ago i tried doing it with a bunch of ifs and elses but with so many characters at once (possibly 8) there were just way too many combinations, it would have taken me about 1000 lines of code just to do that.

at the bottom of the page, just above the reply box is a link that says "Mark As Solved" :) Remember to come back if you need help with your sort

This question has already been answered. Start a new discussion instead.