Checking wich of 3 options has more votes

xoxdragonxox

New Member
Reaction score
1
I have 3 modes by a dialog. Easy, Medium, Hard. I replaced the Array # with the word so its easier for your guys to know which is which. My question is, will this check which of the 3 has the most votes, and is there a more simple way of doing this

JASS:
    if udg_DialogVote[MEDIUM] >= udg_DialogVote[HARD] then
        if udg_DialogVote[EASY] >= udg_DialogVote[MEDIUM] then
            Call Easy Mode Actions
        else
            Call Medium Mode Actions
        endif
    else
        if udg_DialogVote[EASY] >= udg_DialogVote[HARD] then
            Call Easy Mode Actions
        else
            Call Hard Mode Actions
        endif
    endif
 

PurgeandFire

zxcvmkgdfg
Reaction score
508
Yeah that should work. However, just be aware that it won't take into account equal votes. (or rather, it will, but it will choose one of the two instead of doing a revote [unless of course you intend for it to be like that]) :p

In your case, I would stick to that method since you are only comparing 3 values. In other cases where there are a lot more, you should just use a loop for simplicity. (eg: have a local variable named high, and then compare the array variable to "high". If it is higher, then "set high = array" and then after the loop, just do whatever actions correspond to that array) For example:
JASS:
globals
    integer array data
    trigger array triggers
endglobals

function EvaluateHighest takes nothing returns nothing // this probably isn't a practical example
    local integer high = 0  // but if you are going for simplicity, this might work for you
    local integer i    = 0
    loop
        exitwhen i == 12
        if data<i> &gt; high then
            set high = i
        endif
        set i = i + 1 
    endloop
    call TriggerEvaluate(triggers[high])
endfunction</i>
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top