Compare Multiple Variables, Determine Highest One

Is there any way to compare multiple variables and determine the highest one? I'm attempting to create a custom battle system using events, and I need to be able to determine attack order based on the actors'/enemies' speeds. Currently, my setup involves a long list of conditional branch compares that adds 1 to a variable for an entity's attack order if X_spd is >= Y_spd (as well as conditions in which that doesn't happen). This all works fine and dandy, but I need to be able to read the attack order variables to actually determine what character moves when.

If none of that made any sense, here's my (very long) event page.

Spoiler
8VcNJ4F.png

q94GoNi.png

eEQ56qL.png


(This isn't all of it but you get the gist)

I haven't found any method in the program that would allow me to compare the values of multiple variables and program commands based on the results of the comparison, which is what I need. I'm open to using a script if such a thing exists, but if not, I'd like to know how I either can compare multiple vars or possibly rewrite this system to not need to.
I wrote a small snipet for you.
Code:
class Game_Interpreter
    #---------------------------------------------------------------------------
    # * new method: create_orders
    #---------------------------------------------------------------------------
    def create_orders(player_variables,enemies_variables)
      orders = player_variables + enemies_variables
      orders.sort!{|a,b| a[1] <=> b[1]}
      orders.each_with_index do |array_data,index|
        $game_variables[array_data[0]] = index
        p "Variables #{array_data[0]} = #{index}"
      end
      orders
    end
  end
How to use it
upload_2017-6-20_23-41-8.png
Ooh, that looks neat. So I'll be able to check which variable is the highest and redirect to a new event page based on the results?
Yup :3 I just use your original idea. Calculate the order base on speed. The function will return an array, just get the last element then you will get the highest one.
Where does it return the array to?
Code:
Array = create_orders(players, enemies)
Last_element = Array[Array.size - 1]
Sorry, I'm a bit confused. How does that compare all the variables to one another to determine the highest?
Basically, I put all the variable to an array and sort that array from low to high so the last one should be the highest one in th list.

Original thread: https://forums.rpgmakerweb.com/threads/compare-multiple-variables-determine-highest-one.80169/