| 05-05-2005, 05:43 AM | #1 |
I am creating a voting system. When each player votes I used intergers to add the vote. The question is... how do I create a trigger to know when all players are finished voting? Also, how can you compare the different intergers levels to figure out which one has the highest value? Thanks in advance. ~Azhag~ |
| 05-05-2005, 07:50 AM | #2 |
Since you use integers to add the vote for each option, and each player can only vote once (or his previous vote is replaced), then you know the players are all finished voting when NumberOfVotes1 + NumberOfVotes2... = number of players. I think that's what you meant by saying you used integers to add the vote. As for comparing different integers quickly, I guess the best way would be to store all the values in an array, then use two for loops to compare everything with everything else. So assuming you wanted to just take the biggest value, you have an if-else to set the value of the smaller value to 0, so the only value at the end of the loop that is non-zero is the number of votes in the option that was voted for. Errr... like (Not using any specific syntax): For I = 1 to 10; { For J = 1 to 10; { If Option[J] > Option[i] Set Option[i] = 0; Else Set Option[J] = 0; } } Then at the end. For I = 1 to 10; { If Option[i] != 0; Set The_Option_With_Highest_Vote = I; } That's how I would do it. Something like that at least. |
| 05-05-2005, 08:27 AM | #3 | |
Quote:
alternatively, create another integer that decrements when someone votes, starting at number of players, when it gets to 0 everyone is done (if someone leaves it has to decrement too) as for the sorting, you turned a O(n) operation into a O(n^2) operation... extremely inefficient nesting loops and looped again at the end? You're also destroying all the values unless thats a copy of the original array. Code:
set MaxVal = Option[1]
set MaxNum = 1
For int A = 2 to 10
if Option[A] > MaxVal then
MaxVal = Option[A]
MaxNum = A
endif
endloop
//MaxNum is the index for the option with the highest,
//MaxVal is the highest number of votes casted into it |
| 05-05-2005, 10:45 AM | #4 |
First check how many players who playing: 1) For each (Integer A) from 1 to 12, do (Actions) Loop - Actions If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions ((Player((Integer A))) slot status) Equal to Is playing Then - Actions Set PlayerIsPlaying = (PlayerIsPlaying + 1) Else - Actions Then if someone is voting: 2) If a player is voting set variable "VoteingLeft" = (VoteingLeft + 1) Check if all players has vote: 3: If (All Conditions are True) then do (Then Actions) else do (Else Actions) If - Conditions VoteingLeft Equal to PlayerIsPlaying Then - Actions End Voteing |
| 05-05-2005, 03:48 PM | #5 |
Yah. I guess I was inefficient. I was thinking more in the way of sorting and so I sort of thought along the lines of bubble sort instead of going directly to the solution. |
| 05-07-2005, 05:45 AM | #6 |
Alright, I got to when everyone is done voting, it will go through actions. But I am still stuck on when it says which out of all the interger variables, is the greatest. Still need a little help with that. I know Raptor-- answered my question, but a little explanation would help me much. Thanks. ~Azhag~ |
| 05-07-2005, 11:02 AM | #7 |
Download my map here |
| 05-07-2005, 05:33 PM | #8 |
Thank system works great for 3 difficulties, but how do I change it if I want 5? The variable Difficulty_Trigger will only allow Easy Medium and Hard. But I want 5 different difficulties. How can I do this? |
| 05-08-2005, 02:14 PM | #9 |
I have recreated the trigger for the difficulty vote system, its should be easyer to read the trigger now, and i works for 5 difficulty. Very Easy Easy Medium Hard Very Hard |
| 05-08-2005, 06:00 PM | #10 |
Thank you very much.... Very good help. I would give you another rep, but I gotta spread first. :P ~Azhag~ |
