Javascript incredible behaviour!

Hello,

I found an incredible problem in one simple script. I made a script called MyTest, and it contains:

private var conta = 0;

function Update () {

    conta++;
    Debug.Log("eccomi: " + conta);

	if(conta > 10) {
        conta = 0;
        Debug.LogWarning("Counter: " + conta);

    }
}

Well, save it and assign it to any object on the screen. If you execute it, the Debug.Log will stop to write the log when conta=0 is executed!

This is the complete LOG in Unity (only the last lines :slight_smile: ):

eccomi: 7
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Pippo:Update() (at Assets\Scripts\JavaScripts\MassiveCreek\Pippo.js:7)
 
(Filename: Assets/Scripts/JavaScripts/MassiveCreek/Pippo.js Line: 7)

eccomi: 8
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Pippo:Update() (at Assets\Scripts\JavaScripts\MassiveCreek\Pippo.js:7)
 
(Filename: Assets/Scripts/JavaScripts/MassiveCreek/Pippo.js Line: 7)

eccomi: 9
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Pippo:Update() (at Assets\Scripts\JavaScripts\MassiveCreek\Pippo.js:7)
 
(Filename: Assets/Scripts/JavaScripts/MassiveCreek/Pippo.js Line: 7)

eccomi: 10
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Pippo:Update() (at Assets\Scripts\JavaScripts\MassiveCreek\Pippo.js:7)
 
(Filename: Assets/Scripts/JavaScripts/MassiveCreek/Pippo.js Line: 7)

eccomi: 11
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Pippo:Update() (at Assets\Scripts\JavaScripts\MassiveCreek\Pippo.js:7)
 
(Filename: Assets/Scripts/JavaScripts/MassiveCreek/Pippo.js Line: 7)

Counter: 0
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:LogWarning(Object)
Pippo:Update() (at Assets\Scripts\JavaScripts\MassiveCreek\Pippo.js:11)
 
(Filename: Assets/Scripts/JavaScripts/MassiveCreek/Pippo.js Line: 11)

eccomi: 1
UnityEngine.Debug:Internal_Log(Int32, String, Object)
UnityEngine.Debug:Log(Object)
Pippo:Update() (at Assets\Scripts\JavaScripts\MassiveCreek\Pippo.js:7)
 
(Filename: Assets/Scripts/JavaScripts/MassiveCreek/Pippo.js Line: 7)


Unloading 250 unused Assets to reduce memory usage. Loaded Objects now: 920.
System memory in use: 144.8 MB.
Unloading 1 Unused Serialized files (Serialized files now loaded: 2 / Dirty serialized files: 2)

If I eliminate the piece of code “conta=0” it seems it works perfectly!
Even if I use “conta = conta + 1” it works!
It seems the variable reset causes a problem!! SImply incredible!!

Have you any infor about it? Can you check it (very easy to test)!

Thank you for your help!

this is your error
the line

if(conta > 10) {

it’s wrong

UPDATE:

it seems there is a problem with LOG, since this code works:

private var conta = 0;

private static final var MIO_ZERO = 0;

function Update () {

	 if (Input.GetKeyDown (KeyCode.X)) {
	 	Debug.Log("Valore:" + conta);
	 }

    conta++;

	if(conta > 100) {
        conta = 0;
        

    }
}

Hello there!

If you have a careful look at the log you’ll find a button marked “Collapse”.
Should Collapse be enabled all identical lines will be removed so only one of them remains.

Thank you! I was just writing that it seems Console eliminate duplicated messages, but you even gave me the solution! Thank you!!

For @Petaflops : that line is correct and works perfectly. Why do you think it is wrong?