• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

irandom_range "y" works, but not "x"

huenix

Member
Hello,
I am still a beginner in GML coding but I think I understand it for the most part.
I an trying to have enemies random spawn AND not over each as well in the holes/walls (they are both "oCollision", with the stage only.
My 3 problems are:

1) if using place_meeting with JUST "oEnemy"; they spread out, but spawn indies holes&walls AND out side of the stage

2) if using place_meeting with JUST "oCollion"; doesn't spawn in "cCollision", but oEnemy over laps with itself AND makes it's own smaller spawning stage

3) if using both together, all negatives happen, small spawning stage (i didn't make), oEnemy over laps with self's and oCollion


My last issues is that only the "y" irandom_range works, but the x crates a smaller range. 112px about.
no mater what i set the x numbers to, they only make their own spawn range the same every time.
the "y" works with the numbers i give it, not matter what i put. ???
im SO confused by that.


(thank you for any help :)

this is the code as i have it now: (updated from 1st post)



repeat(20)
{
var _xRandomSpawnEnemy = irandom_range(32, 640);
var _yRandomSpawnEnemy = irandom_range(5168, 5776);


while (place_meeting(_xRandomSpawnEnemy, _yRandomSpawnEnemy, oEnemy)) ||
(place_meeting(_xRandomSpawnEnemy, _yRandomSpawnEnemy, oCollision))

{
_xRandomSpawnEnemy = irandom_range(32, 640);
_yRandomSpawnEnemy = irandom_range(5168, 5776);
}

instance_create_layer(_xRandomSpawnEnemy, _yRandomSpawnEnemy,"Enemy",oEnemy);

}
 
Last edited:

FrostyCat

Redemption Seeker
Change the && to ||. Right now you are forcing BOTH collisions to be active in order to find a new spot, but you want EITHER OR BOTH collisions to be active in order to find a new spot. Learning to use truth tables to model your needs helps avoid these silly mistakes.
 

huenix

Member
Change the && to ||. Right now you are forcing BOTH collisions to be active in order to find a new spot, but you want EITHER OR BOTH collisions to be active in order to find a new spot. Learning to use truth tables to model your needs helps avoid these silly mistakes.
wow... i feel stupid :( ....
THANK YOU....

now to my last issue... it keeps making the spawn area small than what i am setting it to.
no matter how many times i restart, they do not fill out the room. it looks like it takes off 112 px from both sides (xmin and x max)
 
Top