• 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!

[SOLVED] distance_to_object infinite loop

K

kirkkaf13

Guest
Hi everyone,

I recently purchased GMS;Professional after not using the software since the early version 4 back in 2001 and wow has the software developed into something special!

I have a fair bit of experience programming in Java creating android applications for medical devices at a small firm so I am familiar with the concepts. Although I am having some trouble with a small script to generate my level.

I have a script that generates various objects in the world during startup this works fine. The trouble was they were sometimes being created too close to each other. I tried to avoid this by checking the distance of the objects during creation using the distance_to_object but now my game window doesn't appear.

First I thought this could be a performance hit as it couldn't find a suitable location far enough away from other objects which caused it keep looping. After generating less objects and changing the allowed distance it still didn't show the game window. Removing this small check and the window does appear again.

Code:
while (distance_to_object(obj_wall  < 30))
{
    x = random(room_width);
    y = random(room_height);   
}
Hope this makes sense, any ideas?

Kirk
 
Top