# Issue with boolean changing values in object

**URL:** <https://forum.kirupa.com/t/issue-with-boolean-changing-values-in-object/316196>\
**Category:** Uncategorized\
**Created:** [November 15, 2010, 10:50pm UTC](https://forum.kirupa.com/t/issue-with-boolean-changing-values-in-object/316196 "2010-11-15T22:50:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![danthebeliever](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@danthebeliever](https://forum.kirupa.com/u/danthebeliever)\
**Post date:** [November 15, 2010, 10:50pm UTC](https://forum.kirupa.com/t/issue-with-boolean-changing-values-in-object/316196/1 "2010-11-15T22:50:27Z")

</div>

Hello! Still working on a fun little fishing game for as3.

I have a question about objects, when I set a variable equal to false in my object via the setRight() method, the boolean value does not remain false after the first function call.

Here is the object “Fish”

```auto

var attached:Boolean = false;
var left:Boolean = true;
var speed:int = 2;
    
function setLeft():void{
    this.left = true;
}
function setRight():void{
    this.left = false;
    this.rotation = 90;
    trace("left is: " + left);
}
function moveFish():void{
    trace(this.left);
    if(this.left){
        this.x -= speed;
    } else {
        trace("what up stud");
        this.x += speed;
    }
}

stop();

```

Here is the “driver”

```auto
stage.focus = this;

var boatMove:Number = 20;
var moveSpeed:Number = 4.7;
var harpMoving:Boolean = false;
var curScore:int = 0;

var Fish:aFish = new aFish();
Fish.setLeft();
Fish.x = 550;
Fish.y = 250;
stage.addChild(Fish);

stage.addEventListener(KeyboardEvent.KEY_DOWN,boatMover);
stage.addEventListener(KeyboardEvent.KEY_UP, harpMover);
stage.addEventListener(Event.ENTER_FRAME, everyFrame);this.Boat.Harpoon
function boatMover(event:KeyboardEvent):void{
    
    if(event.keyCode == Keyboard.LEFT && Boat.x >= 0 ){
        Boat.x -= boatMove;
    }
    if(event.keyCode == Keyboard.RIGHT && Boat.x <= 450 ){this.Boat.Harpoon
        Boat.x += boatMove;
    }
    if(event.keyCode == Keyboard.DOWN){
        harpMoving = true;
        if(Boat.Harpoon.height >= 290){
            harpMoving = false;
        }
    }
}
function harpMover(event:KeyboardEvent):void{
    harpMoving = false;
}
function everyFrame(event:Event):void{
    if(harpMoving){
        Boat.Harpoon.height += moveSpeed;
        Boat.HarpoonStick.y += moveSpeed;
    }
    if(!harpMoving && Boat.Harpoon.height >= 1 && Boat.HarpoonStick.y >= 5){
        Boat.Harpoon.height -= moveSpeed;
        Boat.HarpoonStick.y -= moveSpeed;
        if(Boat.HarpoonStick.hitTestObject(Fish.hitBox) && Fish.attached == false){
            curScore++;
            this.aTextBox.text = curScore.toString();
            Fish.gotoAndPlay(2);
            Fish.attached = true;
        }
        if(Fish.attached == true){
            Fish.y -= moveSpeed;
        }
    }
    if(Fish.hitTestObject(Boat.theBoat)){
        stage.removeChild(Fish);
    }
    if(!Fish.attached){
        Fish.moveFish();
    }
    
}

```

You can replicate the error by changing these linesof code in the driver:

```auto

//original

Fish.setLeft();
Fish.x = 550;
Fish.y = 250;

// change

Fish.setRight();
Fish.x = 0;
Fish.y = 250;

```

With the change, the fish should move to the right, but the boolean value “left” does not remain to be false, it stays as true.

And here is a link to the.fla  
[https://bearspace.baylor.edu:443/Dan\_Johnson/public/flashFun/goneFishin%27.fla](https://bearspace.baylor.edu/Dan_Johnson/public/flashFun/goneFishin%27.fla)
