# Making a sprite move in directions from a list in an array?

**URL:** <https://forum.kirupa.com/t/making-a-sprite-move-in-directions-from-a-list-in-an-array/214287>\
**Category:** Uncategorized\
**Created:** [January 26, 2007, 11:52pm UTC](https://forum.kirupa.com/t/making-a-sprite-move-in-directions-from-a-list-in-an-array/214287 "2007-01-26T23:52:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kingscooty](https://avatars.discourse-cdn.com/v4/letter/k/73ab20/32.png) [@kingscooty](https://forum.kirupa.com/u/kingscooty)\
**Post date:** [January 26, 2007, 11:52pm UTC](https://forum.kirupa.com/t/making-a-sprite-move-in-directions-from-a-list-in-an-array/214287/1 "2007-01-26T23:52:00Z")

</div>

I found myself confused again while experimenting with flashy ☹ was hoping you wonderful people may have the answer once again :)!.  
I wanted a sprite to move round on the screen when a play button was pushed. I have a left and a right button which store strings “left” or “right” into the next positions of an empty array called history.

When i push the play button i want i want the sprite to move either left or right according to what commands are in the array. My code just seems to play one single command and then stops ☹ when i hit play again it just repeats the same command.

Is there any way to make it play through all commands in the array one after another?

Here’s the loop that i was trying to use.

```php
 if (historyPlay == true) 
 {
  for (var i = 0; i< history.length; i++) 
  {
   switch (history*) {
    case "left" :
     if (sprite.facing == "N") {
      sprite.facing = "W";
     } else if (sprite.facing == "W") {
      sprite.facing = "S";
     } else if (sprite.facing == "S") {
      sprite.facing = "E";
     } else if (sprite.facing == "E") {
      sprite.facing = "N";
     }
     dir = "left"
     this.moving = true
    break;
    case "right" :
     if (sprite.facing == "N") {
      sprite.facing = "E";
     } else if (sprite.facing == "E") {
      sprite.facing = "S";
     } else if (sprite.facing == "S") {
      sprite.facing = "W";
     } else if (sprite.facing == "W") {
      sprite.facing = "N";
     }
     dir = "left"
     this.moving = true
    break;
   }
  }
  historyPlay = false;
 }

```

Thanks in advanced! 🙂
