S
SimonB
Guest
I have the following code in the create event of a controller object:
var rock
repeat(6)
{
rock=instance_create(random(room_width),random(room_height),object_rocket);
do
{
rock.x = random(room_width);
rock.y = random(room_height);
}
until (place_empty(rock.x,rock.y));
}
It doesn't work as I expect it to and the rockets overlap with other objects in the room. I can get it to work by putting the do loop in the create event of the rocket, but I want to understand why this doesn't work. By playing around with it, I'm pretty certain it just changes the position once then repeats, rather than looping through until nothing overlaps. If someone can explain it to me please, I'd be very grateful. My apologies if it's staring me in the face and I just can't see it!
var rock
repeat(6)
{
rock=instance_create(random(room_width),random(room_height),object_rocket);
do
{
rock.x = random(room_width);
rock.y = random(room_height);
}
until (place_empty(rock.x,rock.y));
}
It doesn't work as I expect it to and the rockets overlap with other objects in the room. I can get it to work by putting the do loop in the create event of the rocket, but I want to understand why this doesn't work. By playing around with it, I'm pretty certain it just changes the position once then repeats, rather than looping through until nothing overlaps. If someone can explain it to me please, I'd be very grateful. My apologies if it's staring me in the face and I just can't see it!