# Use boolean, Or just reassign property?

**URL:** <https://forum.kirupa.com/t/use-boolean-or-just-reassign-property/319683>\
**Category:** Uncategorized\
**Created:** [March 1, 2011, 4:57pm UTC](https://forum.kirupa.com/t/use-boolean-or-just-reassign-property/319683 "2011-03-01T16:57:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbo](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@tbo](https://forum.kirupa.com/u/tbo)\
**Post date:** [March 1, 2011, 4:57pm UTC](https://forum.kirupa.com/t/use-boolean-or-just-reassign-property/319683/1 "2011-03-01T16:57:34Z")

</div>

I \*think \*the answer to this is a case by case basis but sometimes i wonder if i should check if a property needs to be assigned, or should i just assign it regardless. Specifically in the main game loop, so its happening constantly.

take this example of flipping the players scaleX when traveling the opposite direction:

```php

var vx:Number=1;//velocity x

addEventListener(Event.ENTER_FRAME, enterFrameHandler);

function enterFrameHandler(e:Event)
{
    if (vx < 0 && player.scaleX != -1)
    {
        player.scaleX = -1;
    }
    else if (vx>=0 && player.scaleX!=1)
    {
        player.scaleX = 1;
    }
}

```

I believe booleans are among the fastest check right? so perhaps this would be slightly faster

```php
var flipped:Boolean;

function enterFrameHandler(e:Event)
{
    if (vx < 0 && !flipped)
    {
        flipped=true;
        player.scaleX = -1;
    }
    else if (vx>=0 && flipped)
    {
        flipped=false;
        player.scaleX = 1;
    }
}

```

but sometimes i say \*\*\*\* it and just assign it every frame whether it needs it or not.

```php
function enterFrameHandler(e:Event)
{
    if (vx < 0)
    {
        player.scaleX = -1;
    }
    else
    {
        player.scaleX = 1;
    }
}

```

with velocity of course player will slow down before actually changing directions, otherwise i would assign the scaleX once on a key press or event triggering the turn around.

Thanks for any thoughts on this. In this example none of them are going to create a noticeable slow down (i don’t think). Sometimes i find myself doing similar things and i don’t have a uniformed method on the matter. I guess the best answer is, what ever will keep my game loop function running fastest? (in an average state that is)
