Jump to content

[SOLVED] Actionscript Help: auto populating array random


chmpdog

Recommended Posts

Hi, Im new to actionscript, but I decided to give it a shot in a new flash game I am making. So far everything is going great, but I have a "random" gamemode for this new game, where it basically does Math.Random for and decides which frame it goes to.

 

But here is the problem: often times it brings me back to the same frame, or a previous frame I have already played. So what can I do so that it doesn't go back to the same frame?

 

thank-you

Why don't you store all the playable frames inside an array and shuffle it? That way you can simple increase the array key by one each time you enter a new game thus not having to check if you already played the game.

never mind I found it. Thank You.

 

Array.prototype.shuffle=function(){

  for(i=0;i<this.length;i++){

      var tmp=this;

      var randomNum=random(this.length);

      this=this[randomNum];

      this[randomNum]=tmp;

  }

}

 

 

arr1=["a","b","c","d","e"];

arr1.shuffle();

trace(arr1);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.