Jump to content

[SOLVED] Actionscript Help: auto populating array random


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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.