I am dissapointed in this language.


var global_1:array=[false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false]; //cards array function func_1():array {      var loc_1:int=0;       var loc_2:boolean=false;      var loc_3:array=["?",nan,nan,nan];//structure: [name,number,type,value]       var loc_4:string="?"; //name of card      var loc_5:int=0;      while (!loc_2 && loc_5 < global_1.length) {                 //while hasn't found avaible card before going though deck           loc_1=math.round(math.random()*global_1.length);           loc_5++;           if (!global_1[loc_1]) {                         //if card it's checking avaible                global_1[loc_1]=true;//marks card used                loc_2=true;//it tells comp found card                 if (loc_1%13<9) {                     loc_4=""+int(loc_1+2);                }                if (loc_1%13==9) {                     loc_4="j";                }                if (loc_1%13==10) {                     loc_4="q";                }                if (loc_1%13==11) {                     loc_4="k";                }                if (loc_1%13==12) {                     loc_4="a";                }//tells card type                loc_3=[loc_4,loc_1%13,loc_1%4,loc_1];//puts card information in array           }      }      return loc_3; // returns array }  var global_2:array=[]; (var for_1:int; for_1 < 100; for_1++) {      global_2.push(func_1()); } trace(global_2); 

i didn't have compile errors , nor did have runtime errors. yet code doesn't work properly. dissapointed.

i using: flash cs4 pro, flash player 10, actionscript 3. commented of lines wants understand code.

this line returns random value 0 52, highest array index 51

loc_1=math.round(math.random()*global_1.length)

 

so when loc_1 greater global_1.length -1, you're pushing new element array:

global_1[loc_1]=true; //marks card used

 

 

change to:

loc_1=math.round(math.random()*(global_1.length-1));



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

CS5 Adobe Media Encoder: Encode failed because the source duration is nil.

cf_sql_integer vs cf_sql_bigint vs cf_sql_int??

localhost/joomla15/administrator doesnt work - Joomla! Forum - community, help and support