HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need a bit of a help with a dialog voting system

06-14-2009, 08:52 PM#1
doom-HaMsTeR
Hi

I'm having a bit of trouble. I'm making a map which has voting as one of its core things. I've got the dialog part all sorted and the whats been voted for part all sorted too, but I've got a bit of a problem with the counting of the vote. I need it as a maximum of 8 options, so at the moment its 'if Option1 is greater than Option2', 'if Option 1 is greater than Option 3' etc etc, which does work if a bit clunky. But if the vote is a tie, how would I go about working out what is tied without making hundreds of if/then/elses?

I'm sure theres a simpler way than what I've got atm (maybe using 'for each integer'? I'm a noob when it comes to using that), or if not, one that at least sorts out ties easily. I'm afraid that I'm totally JASS-illiterate; I've never used it before in my life, so if I need to use that... If anyone can help, it'd be much appreciated.

Thanks
06-14-2009, 09:04 PM#2
Opossum
I would use a single array for all 8 options and them compare them in a loop like:
Trigger:
For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Option[(Integer A)] greater than MaxOption
Collapse Then - Actions
Set MaxOption = (Integer A)
Else - Actions
If two options have an equal vote count then the one that comes first in the array will be chosen.
06-14-2009, 09:30 PM#3
doom-HaMsTeR
Cheers Opossum, and that definitely works better than what I've got atm...but I want it so that players are voted out (not a boot system), and the map is based around players being voted out. Your system is a bit unfair on the player who comes first in the array.

Thanks very much though, thats certainly better than the system that I was using. I just need to find a way of sorting out a tie, its confusing me. :D
06-15-2009, 01:39 PM#4
snowtiger
You could always just do another loop trough all the options and check if the value is the same as the maximum value
Trigger:
Collapse For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Option[(Integer A)] greater than MaxOption
Collapse Then - Actions
Set MaxOption = (Integer A)
Else - Actions
Collapse For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
Option[(Integer A)] equal to MaxOption
Collapse Then - Actions
// do stuff here that should be done when there is a tie
Else - Actions

This is probably not the best solution, but I think that it does at least work.
06-15-2009, 02:11 PM#5
Opossum
I just noticed that my loop is total bollocks actually. You need two additional variables instead of one:
MaxOption and MaxOptionCount
Trigger:
For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
OptionCount[(Integer A)] greater than MaxOptionCount
Collapse Then - Actions
Set MaxOption = (Integer A)
Set MaxOptionCount = OptionCount[(Integer A)]
Else - Actions

Edit: No you actually don't. This should be enough too:
Trigger:
For each (Integer A) from 1 to 8, do (Actions)
Collapse Loop - Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
OptionCount[(Integer A)] greater than OptionCount[MaxOption]
Collapse Then - Actions
Set MaxOption = (Integer A)
Else - Actions
I blame GUI for this confusion :\