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

**URL:** <https://forum.kirupa.com/t/can-i-change-truth01-visible-from-anywhere-in-code-vs-this-visible/634506>\
**Category:** programming\
**Created:** [April 16, 2016, 12:38am UTC](https://forum.kirupa.com/t/can-i-change-truth01-visible-from-anywhere-in-code-vs-this-visible/634506 "2016-04-16T00:38:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)\
**Post date:** [April 16, 2016, 12:38am UTC](https://forum.kirupa.com/t/can-i-change-truth01-visible-from-anywhere-in-code-vs-this-visible/634506/1 "2016-04-16T00:38:16Z")

</div>

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:

```auto
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

```auto
			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](http://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

---

<div class="post-metadata">

**Author:** ![vmars316](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vmars316](https://forum.kirupa.com/u/vmars316)\
**Post date:** [April 16, 2016, 6:32pm UTC](https://forum.kirupa.com/t/can-i-change-truth01-visible-from-anywhere-in-code-vs-this-visible/634506/2 "2016-04-16T18:32:04Z")

</div>

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](http://liesandcowpies.com/javascript/BenghaziGame-starter-prob01.html)

Thanks.
