Search Unity

Debug.Log and changing in Console

Discussion in 'Getting Started' started by darthachill, Jan 29, 2015.

  1. darthachill

    darthachill

    Joined:
    Jan 25, 2015
    Posts:
    27
    I wonder, Why Debug numer 1 show label in console every time when i'm using Mouse scrollWheel,
    and number 2 not., though value of CurrentWeapon is changing. That make me crazy, when i use solution numer 2, and I see that my program doesn't work well.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class SwitchWeapon : MonoBehaviour
    5. {
    6.     int currentWeapon = 0;
    7.     int maxWeapon = 2;
    8.     int i = 0;
    9.    
    10.     void Update()
    11.     {
    12.         if (Input.GetAxis("Mouse ScrollWheel") > 0)
    13.         {
    14.             if (currentWeapon == maxWeapon)
    15.                 currentWeapon = 0;
    16.             else
    17.                 currentWeapon++;
    18.             i++;
    19.         }
    20.         Debug.Log("loop " + i + " CurrentWeapon " + currentWeapon); // numer 1
    21.         Debug.Log(" CurrentWeapon " + currentWeapon);               // numer 2
    22.     }
    23. }
    24.  
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The console has the collaps option to not show duplications of the same message. Your second message will become such a duplicate after a short amount of time, which is not the case for the first one.
    It is a really practically useful annoying misleading function.
     
  3. darthachill

    darthachill

    Joined:
    Jan 25, 2015
    Posts:
    27
    I agree, in case when condition if(false), we have duplicate, but otherwise I thought that both messages will change, becouse we are changing values( i, currentWeapon) in one block if. So that make no sense. I still ton't understand :D

    now my variable is public, so I can see change,
     
  4. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    The message of the second Debug.Log can be
    • CurrentWeapon 0
    • CurrentWeapon 1
    • CurrentWeapon 2
    If those messages were written once in the console, they won't appear anymore if you have the Collapse option enabled. You find this option at in the console window at the top left, between Clear and Clear on Play. Disable the Collapse option to get the expected result.
    This has nothing to do with your code!
     
    darthachill likes this.