Comparing Variables to find the largest one

I'm using RMXP. I'm trying to compare variables to find the largest value. I found this script
v = $game_variablesm = [v[26], v[27], v[28], v[29] v[30]].maxr = []r.push(26) if v[26] == mr.push(27) if v[27] == mr.push(28) if v[28] == mr.push(29) if v[29] == mr.push(30) if v[30] == m$game_variables[41] = r[rand(r.size)] but it seems to keep coming up as an error. I don't have much experience programming, so any help would be nice
You can add this script, which will give you the $game_variable ID that holds the largest value:
Ruby:
class Interpreter
  def largest_variable(*args)
    max_id = args.shift
    max_val = $game_variables[max_id]
    args.each do |id|
      val = $game_variables[id]
      if val > max_val
        max_id = id
        max_val = val
      end
    end
    max_id
  end
end
And use a Script Call like so:
Code:
id = largest_variable(26,27,28,29,30)
What you do with the resulting id is up to you.

You should fix your post by using code tags so you don't destroy the formatting.
[CODE]your code here[/CODE]
but it seems to keep coming up as an error

does it give you an error message?

If that script is all on one line like you have it there, yes, it's wrong. It should be over multiple lines and the formatting has been lost.

Original thread: https://forums.rpgmakerweb.com/threads/comparing-variables-to-find-the-largest-one.118729/