Can I change 'truth01.visible from anywhere in code' vs this.visible ?

Thanks in advance ,
I am writting a small game program with two sprites that travel back and forth across the canvas .
When one is visible , the other is not .
The 1st sprite works fine .
But I am having trouble getting the 2nd one to work.
The sprites are defined like this:

function startGame() {
	truth01 = new TargetImages();
		truth01.idTag = "truth01";
		truth01.x = 0;
		truth01.y = 40;
		truth01.width = 64;
		truth01.height = 64;
		truth01.speedX = 1;
		truth01.speedY = 0;
		truth01.tripsCnt =0;
		truth01.tripsMax=2;
		truth01.visible = true;
		truth01.directionX = 1;
	lies01 = new TargetImages();
		lies01.idTag = "lies01";
		lies01.x = 0;
		lies01.y = 180;
		lies01.width = 64;
		lies01.height = 64;
		lies01.speedX = 1;
		lies01.speedY = 0;
		lies01.tripsCnt =0;
		lies01.tripsMax=2;
		lies01.visible = false;
		lies01.directionX = 1;

    myGameArea.start();
}

var TargetImages = (function () {
		function TargetImages() {
		    this.nameTag = 'truth01'
            this.x = 0;
            this.y = 0;
			this.width= 32;
			this.height = 32;
			this.speedX = 1;
			this.speedY = 0;
			this.tripsCnt =0;
			this.tripsMax=2;
			this.visible = true; 
			this.directionX = 1;
			this.update = function() {

The code that is’nt working is in this block of code:
line 105

			if(this.tripsCnt > this.tripsMax) {
					if(idTag = "truth01") {truth01.speedX = 0;  truth01.tripsCnt =0;  truth01.visible=false;  lies01.visible=true;  lies01.speedX=1;  
					}
				alert('TRIPsMAX: truth01.visible= ' + truth01.visible +  '  ,      lies01.visible= ' + lies01.visible + '    \ntotalTripsCnt= ' + totalTrips);

					if(idTag = "lies01") {lies01.speedX = 0;  lies01.tripsCnt =0;  truth01.visible=true;  lies01.visible=false;  truth01.speedX=1; 
					}
				alert('TRIPsMAX: truth01.visible= ' + truth01.visible +  '  ,      lies01.visible= ' + lies01.visible + '    \ntotalTripsCnt= ' + totalTrips);

			}

The program runs here:
liesandcowpies.com/javascript/BenghaziGame-starter-prob01.html
The whole js code is within the html file , so its easy to view by doing a right-click on screen and selecting ‘view source’ from popup menu .
Thanks

Well , I am happy to say , I solved prob:
I coded a mix-up between idTag and this.idTag .

And in answer to my own question .
I can use either this.idTag and truth01.idTag anywhere in code
You can see fixed code at
liesandcowpies.com/javascript/BenghaziGame-starter-prob01.html

Thanks.

2 Likes