PDA

View Full Version : F5 problem



Zeroc
February 11th, 2003, 03:03 AM
Hi! Im new with actionscript and wanders whats wrong with this code..I want "unit" to start at a random place where the value is 0 I have got it to work so it starts at a random place but sometimes on 1.. this code dont work! But i hope it shows what i want to do.


map = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
,1,1,1],
[1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,1],
[1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,0,1,1,1,0,0,0
,0,0,1],
[1,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0
,1,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0
,0,0,1],
[1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0
,0,0,1],
[1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,1,1
,0,0,1],
[1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0
,0,0,1],
[1,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0
,0,0,1],
[1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0
,0,1,1],
[1,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,1,0,0,1,0,0
,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,1,0,0,0,0
,1,0,1],
[1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0
,1,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
,1,1,1]
];
// x,y
mappos = false;
for ( mappos = true ); {
unitxpos = Math.round(Math.random()*(2-27))+27;
unitypos = Math.round(Math.random()*(2-13))+13;
unit = [[unitxpos,unitypos]];
if ( map[unit] == 0 ); {
mappos = true;
}



(Sorry for the poor english)

pom
February 11th, 2003, 03:07 AM
Be careful with the line breaks, and your for loop is malformed.

pom :cowboy:

Zeroc
February 11th, 2003, 03:40 AM
I dont have the line breakt in the code I dont know why they got there..

how is a working for loop?

pom
February 11th, 2003, 06:19 AM
It's explained in the AS dictionary :)

for (init;limit;increment){
// statements
}

senocular
February 11th, 2003, 09:38 AM
sounds like youd want a while loop

mappos = false;
while ( mappos == false ); {
// yada yada yada
if ( map[unit] == 0 ); {
mappos = true;
}
}