Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

is unity broken?

Discussion in 'Editor & General Support' started by bedorlan, Apr 3, 2020.

  1. bedorlan

    bedorlan

    Joined:
    Aug 16, 2015
    Posts:
    18
    this code:

    Code (CSharp):
    1.  
    2. internal void TimerOver()
    3.     {
    4.         matchOver = true;
    5.         client.Disconnect();
    6.  
    7.         // todo: votes count should come from the server
    8.         var playerVotes = votesCounters.ConvertAll(voter => voter.GetComponent<VotesCountBehaviour>().GetVotes());
    9.         var myVotes = playerVotes[playerNumber];
    10.         Debug.Log("initial");
    11.         Debug.Log("0=" + playerVotes[0].ToString());
    12.         Debug.Log("1=" + playerVotes[1].ToString());
    13.         playerVotes.Sort();
    14.         Debug.Log("after sort");
    15.         Debug.Log("0=" + playerVotes[0].ToString());
    16.         Debug.Log("1=" + playerVotes[1].ToString());
    17.         playerVotes.Reverse();
    18.         Debug.Log("after reverse");
    19.         Debug.Log("0=" + playerVotes[0].ToString());
    20.         Debug.Log("1=" + playerVotes[1].ToString());
    21.         var maxVotes = playerVotes[0];
    22.         Debug.Log("after max");
    23.         Debug.Log("0=" + playerVotes[0].ToString());
    24.         Debug.Log("1=" + playerVotes[1].ToString());
    25.  
    26.         var iWin = myVotes == maxVotes;
    27.         var draw = playerVotes[0] == playerVotes[1];
    28.         OnMatchEnd?.Invoke(draw, iWin);
    29.     }
    30.  
    print this:

    Code (CSharp):
    1. initial
    2. 0=0
    3. 1=-12
    4. after sort
    5. 0=-12
    6. 1=0
    7. after reverse
    8. 0=0
    9. 1=0
    10. after max
    11. 0=0
    12. 1=0
    13.  
    but whyyyyy?

    Screen Shot 2020-04-02 at 10.48.37 PM.png
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Im unsure what kind of data structure you are using, but i testet it with a list and id did result in the expected results:

     
  3. bedorlan

    bedorlan

    Joined:
    Aug 16, 2015
    Posts:
    18
    yeah, me too, is very crazy!
    playerVotes is List<int>

    any ideas?
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Make some check , just fill the list with dummy data and see how it reacts.
    Can you make a copy of the original data and work with that.
    Does the original data gets somehow external changed.
     
  5. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,000
    and check how many items there is in that list
     
  6. bedorlan

    bedorlan

    Joined:
    Aug 16, 2015
    Posts:
    18
    yeess! i feel so dumb! thank you!