# Hmm

**URL:** <https://forum.kirupa.com/t/hmm/8956>\
**Category:** Uncategorized\
**Created:** [December 1, 2002, 10:43pm UTC](https://forum.kirupa.com/t/hmm/8956 "2002-12-01T22:43:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ORNj](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@ORNj](https://forum.kirupa.com/u/ORNj)\
**Post date:** [December 1, 2002, 10:43pm UTC](https://forum.kirupa.com/t/hmm/8956/1 "2002-12-01T22:43:19Z")

</div>

ok here’s the deal. I want to make this little guy that moves left or right across the screen until he reaches a point which I have told him that he can not pass. At that point I want him to turn around and head the other direction until he reaches the next point that I told him not to pass. this is what i have so far:

onClipEvent(load)  
{  
//moves enemy to the left  
function totheleft()  
{  
var wierdoSpeed=5;  
this.\_x-=wierdoSpeed;  
}  
//moves enemy to the right  
function totheright()  
{  
var wierdoSpeed=5;  
this.\_x+=wierdoSpeed;  
}   
}  
onClipEvent(enterFrame)  
{  
var mymaxleft=10, mymaxright=350;  
if(this.\_x\>mymaxleft)  
totheleft();

With this code the guy goes to the left and stops at x=10, success, but now I’m not sure where to go from here to make him head back to x=350.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [December 2, 2002, 12:10am UTC](https://forum.kirupa.com/t/hmm/8956/2 "2002-12-02T00:10:03Z")

</div>

```auto

onClipEvent(load){
   max = 350;
   min = 10;
   speed = 5;
   function left(){
      if((this._x -= this.speed) < this.min){
         this.onEnterFrame = right;
      }
   }
   function right(){
      if((this._x += this.speed) > this.max){
         this.onEnterFrame = left;
      }
   }
   this.onEnterFrame = right;
}

```
