new Array(); question, sorry!
- Started
- Last post
- 9 Responses
- goygoygoy
I have this:
matriceX = new Array();
matriceY = new Array();
for (i=0; i<6; i++) {
posX = 35*Math.round(Math.random()*5);
posY = 35*Math.round(Math.random()*5);matriceX.push(posX);
matriceY.push(posY);
}
so each iteration creates me a position x,y. is there a way to test that if a position already exists, it has to recalculate it, then store it in the arrays then recalculate and so on...?thks in advance.
note: maybe it would be easier to store positions [x,y] in just one array but I don't see how to do it.
- unfittoprint0
Make the random/round thing a function.
Then you'll have to do a for loop inside the main for loop together with an if statement. The 'insider loop' will check each array cell to see if the value matches it. If not, stores it. If it matchs it, the random/round function is called to find a new value...
- Hardcore0
Try using an array of objects;
calculatePos = function() {
return 35*Math.round(Math.random
()*5);}
MatriceArray = new Array()
for (i=0; i<6; i++) {
Matrice = new Object()
Matrice.x = calculatePos()
Matrice.y = calculatePos()MatriceArray[i] = Matrice
}
now you can access the array using :
xValue = MatriceArray[0].x
yValue = MatriceArray[0].ythen test the xValue and yValues for each position in the array in a different loop - and recalculate the position as necessary...
Not tested - just made up off the top of me head... hope this helps (a little) ... :)
- goygoygoy0
i'll try that, thks.
actually my problem is more syntaxis than logic.thinknig the problem is not a problem, the problem is more speaking with flash.
woow so much problems. life is sooo difficult
>[°v°]<
- jg_20
>[°v°]<
actually that was difficult goygoygoy!
lol
- goygoygoy0
note:
posting AS problems in NT always learn me new things about coding. dawn I love that site, and mostly all NT'ers
I love you all.
snifI feel less alone with you guys.
- goygoygoy0
nice site and works jg_2!
are you in bcn you lucky bastard?, I used to live there 6 months ago.
evophat-interactives&audio son la hostia!resnif.
- frankbb0
did you solve it.. or are you still looking??
- goygoygoy0
actually, I though I solved it. but not. I can't test that if a position already exists, recalculate...
I've it like that:calculatePos = function () {
return 35*Math.round(Math.random()*5);
};
matrice = new Array();
duo = new Object();
for (i=0; i1) {
for (j=0; j<L; j++) {
if (xValue == matrice[j].x) {
trace("oups");
}
}
}... but no
- unfittoprint0
you're using the position function before the inner loop right? Try putting one (or two) more trace actions in 'strategic places' to see if everything it's OK.