F5 problem

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)

Be careful with the line breaks, and your for loop is malformed.

pom :cowboy:

I dont have the line breakt in the code I dont know why they got there…

how is a working for loop?

It’s explained in the AS dictionary :slight_smile:

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

sounds like youd want a while loop

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