chmpdog Posted July 11, 2009 Share Posted July 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/165573-solved-actionscript-help-auto-populating-array-random/ Share on other sites More sharing options...
trq Posted July 11, 2009 Share Posted July 11, 2009 Execute your random function recursively until it lands on a frame that isn't the current frame. Quote Link to comment https://forums.phpfreaks.com/topic/165573-solved-actionscript-help-auto-populating-array-random/#findComment-873411 Share on other sites More sharing options...
chmpdog Posted July 13, 2009 Author Share Posted July 13, 2009 But what about the other frames they have already visited? How can I log this? Quote Link to comment https://forums.phpfreaks.com/topic/165573-solved-actionscript-help-auto-populating-array-random/#findComment-874835 Share on other sites More sharing options...
trq Posted July 14, 2009 Share Posted July 14, 2009 Store them somewhere (like an array) then check against this storage. Its logical thinking, not rocket science Quote Link to comment https://forums.phpfreaks.com/topic/165573-solved-actionscript-help-auto-populating-array-random/#findComment-875027 Share on other sites More sharing options...
RichardRotterdam Posted July 14, 2009 Share Posted July 14, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/165573-solved-actionscript-help-auto-populating-array-random/#findComment-875045 Share on other sites More sharing options...
chmpdog Posted July 14, 2009 Author Share Posted July 14, 2009 how would you shuffle it? Quote Link to comment https://forums.phpfreaks.com/topic/165573-solved-actionscript-help-auto-populating-array-random/#findComment-875342 Share on other sites More sharing options...
chmpdog Posted July 14, 2009 Author Share Posted July 14, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/165573-solved-actionscript-help-auto-populating-array-random/#findComment-875346 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.