Reset correctly a Timeout? clearTimeout(var); ?

How to clear a Timeout in a var ??


I try many tricks, but no one work.


The timer , never reset correctly.


If i click fast, the timer doesn't reset and make some bad thing


Tank you guys

Code:
function AvatarAnim(WhatToDo,ID) { //when run this function do this
if (WhatToDo == 'SHOW') {
$gameScreen.showPicture(ID, 'H1-IDLE-talking-happy-6', 1, -280, GameReScreenY-250, 100, 100, 255, 0);
$gameScreen.picture(ID)._angle = -40;
new IAVRA.ANIMATE.Tween($gameScreen.picture(ID), {  _x: 160,_angle: 0, _scaleY: 100 }).easing(IAVRA.EASING.quad.out).duration(20).start();
  
// here clear timer inside the var timerAvatar if exist
clearTimeout(timerAvatar);
 // here add new timer to var timerAvatar with 500 MS
var timerAvatar = setTimeout(function() {$gameScreen.showPicture(ID, 'H1-IDLE-0', 1, $gameScreen.picture(ID)._x, $gameScreen.picture(ID)._y, 100, 100, 255, 0); }, 500);;
}
}
I'm confused as to what the problem is, clearTimeout is correct. What do you mean the timer doesn't reset properly?
I'm confused as to what the problem is, clearTimeout is correct. What do you mean the timer doesn't reset properly?



i Fix the issus.


I change the 


var timerAvatar


by 


timerAvatar


And is work.


Is because when call back the full function,


The (var) scope for timerAvatar , make some issues.


But now i fix and this work.

Code:
// At start game declare timerAvatar
timerAvatar = 0;

// _____________________

function AvatarAnim(WhatToDo,ID) { //when run this function do this
if (WhatToDo == 'SHOW') {
$gameScreen.showPicture(ID, 'H1-IDLE-talking-happy-6', 1, -280, GameReScreenY-250, 100, 100, 255, 0);
$gameScreen.picture(ID)._angle = -40;
new IAVRA.ANIMATE.Tween($gameScreen.picture(ID), {  _x: 160,_angle: 0, _scaleY: 100 }).easing(IAVRA.EASING.quad.out).duration(20).start();
  
// here clear timer inside the var timerAvatar if exist
clearTimeout(timerAvatar);
  timerAvatar = 0;
 // here add new timer to var timerAvatar with 500 MS
timerAvatar = setTimeout(function() {$gameScreen.showPicture(ID, 'H1-IDLE-0', 1, $gameScreen.picture(ID)._x, $gameScreen.picture(ID)._y, 100, 100, 255, 0); }, 500);;
}
}

Original thread: https://forums.rpgmakerweb.com/threads/reset-correctly-a-timeout-cleartimeout-var.70361/