# Problem of movement of snake

**URL:** https://forum.kirupa.com/t/problem-of-movement-of-snake/226253
**Category:** Uncategorized
**Created:** [May 19, 2007, 10:58am UTC](https://forum.kirupa.com/t/problem-of-movement-of-snake/226253 "2007-05-19T10:58:36Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![pandu\_kirupa](https://avatars.discourse-cdn.com/v4/letter/p/cab0a1/32.png) [@pandu\_kirupa](https://forum.kirupa.com/u/pandu_kirupa)
#### Post date: [May 19, 2007, 10:58am UTC](https://forum.kirupa.com/t/problem-of-movement-of-snake/226253/1 "2007-05-19T10:58:36Z")

</div>

hi, i am building a snake game, my goal is to build the script in one frame i.e first frame  
but the error comes when i am using arrow keys, the snake is entirely going up or down at once in their exact positions i mean to say that the objects are not following each other i am posting that entire script so that it may be easy to find out the error

i think the total error was in onEnterFrame script so please solve the problem

arr = new Array();  
arrpos = new Array();  
tempposx = 6;  
tempposy = 6;  
condition = -1;  
stateof = condition;

for (i=0;i\<10;i++) {  
attachMovie(“cute”,“cute”+i,i);  
arr\* = eval(“cute”+i);  
tempwidth = arr[0].\_width;  
init = arr\*;  
init.\_x = 100 - tempwidth \* i;  
init.\_y = 300;  
arr\*.x = 6;  
arr\*.y = null;  
}

obj = new Object();

obj.onKeyDown = function () {  
if (Key.isDown(Key.LEFT)) {  
arr[0].x = -6;  
arr[0].y = null;  
signer = -1;  
}  
if (Key.isDown(Key.RIGHT)) {  
arr[0].x = 6;  
arr[0].y = null;  
signer = 1;  
}  
if (Key.isDown(Key.UP)) {  
arr[0].x =null;  
arr[0].y = -6;  
signer = -1;  
}

```
if (Key.isDown(Key.DOWN)) {
    arr[0].x =null;
    arr[0].y = 6;
    signer = 1;
}

tempstore = {x:init._x, y:init._y};
//arrpos.push(tempstore);
//condition = true;

```

}

Key.addListener(obj);

onEnterFrame = function () {  
for (i=0;i\<10;i++) {

```
arr*._x += arr*.x;
arr*._y += arr*.y;

if(arr*.y)
    arr*.x = null;
else(arr*.x)
    arr*.y = null;
    
if(arr*._x &gt; tempstore.x && arr*._x &lt; arr[i-1]._x )
{ arr*.x = null;
        arr*.y = 6 * signer;
}

```

else if(arr\*.\_x \< tempstore.x && arr\*.\_x \> arr[i-1].\_x ){  
arr\*.x = null;  
arr\*.y = 6 \* signer;  
}  
else if(arr\*.\_y \> tempstore.y && arr\*.\_y \< arr[i-1].\_y){  
arr\*.y = null;  
arr\*.x = 6 \* signer;  
}  
else if(arr\*.\_y \< tempstore.y && arr\*.\_y \> arr[i-1].\_y ){  
arr\*.y = null;  
arr\*.x = 6 \* signer;  
}

```
}

```

}
