PDA

View Full Version : hello there, an array question(help?)



trinidad2k1
February 2nd, 2002, 12:45 PM
Hi, I am wondering if any of you might have some advice toward solving a script problem I am having. I am trying to write a game. It should give the viewer 12 non duplicationg randomly choosen clips out of 24. this code is called from an empty clip on stage. So far all it gets me is the same card 12 times over and over.
Thank you
Tk1


onClipEvent(load)
{
possibleCards=["card0","card1","card2","card3","card4","card5","card6","card7","card8","card9","card10","card11","card12","card13","card14","card15","card16","card17","card18","card19","card20","card21","card22","card23","card24"];

&nbsp &nbsp &nbsp &nbsp randomNum=random(possibleCards);
&nbsp &nbsp &nbsp &nbsp {
&nbsp &nbsp &nbsp &nbsp for(i=0;i<12;i++)
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this.attachMovie(possibleCards[randomNum],"layOut"+i,i);
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this["layout"+i]._x=i*200;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this._xscale=25;
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp this._yscale=25;

&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp }

&nbsp &nbsp &nbsp &nbsp }

}

ilyaslamasse
February 2nd, 2002, 12:51 PM
Are you sure that this random(possibleCards); command exists ? I don't know, I thought it was supposed to be an integer.
pom 0]

trinidad2k1
February 2nd, 2002, 01:29 PM
well, it does work as it returns something. and according to what i read it should work. Of course I have been wrong before. I did try a number variable and an i variable w/no successful results
Tk1

suprabeener
February 2nd, 2002, 02:33 PM
i think you want:

randomNum = random(possiblecards.length);

you'll also probably want to remove the card from the array once it's been chosen to avoid choosing it again:

possibleCards.splice(randomNum,1);

that should happen sometime after you've attached the movie.

JokerRa
February 2nd, 2002, 03:15 PM
possibleCards.splice(randomNum,1);

is "splice" a macro script?
<img src=http://www.ezboard.com/intl/aenglish/images/emoticons/embarassed.gif ALT=":o"> I don't know that there is a "splice" macro script..
thanks!!..

suprabeener
February 2nd, 2002, 03:46 PM
splice is an array method

JokerRa
February 3rd, 2002, 03:38 AM
ou I see...
thanks once again...

trinidad2k1
February 3rd, 2002, 03:28 PM
thank you, will give it a shot and hopefully it'll work out.
later
tk1