Question

I'm trying to get a random position in the room without the position colliding against col_obj, here is my code:

w = room_width; 
h = room_height;
of = 32;
// zoek nieuwe lege plaats voor volgende letter op
tx = irandom_range(of,w - of * 2);

ty = irandom_range(of, 570);

var col_obj;
switch(global.room_sel)
{
  case lava_room:
  col_obj = lava_obj;
  break;

  case ice_room:
  col_obj = test;
  break;

  case space_room:
  col_obj = test;
  break;
}

while(place_meeting(tx, ty, col_obj))
{
  ty = irandom_range(of, 570);
  tx = irandom_range(of,w - of * 2);
}

global.room_sel is always lava_room here, so col_obj should be correct.. When I execute this script my while keeps on looping and the game crashes, I have no idea why. And yes, there are free spots in the room that are not taken by the 'col_obj'

Was it helpful?

Solution

Fixed the issue, used

do { //code } until(!place_meeting(tx, ty, col_obj)) 

instead.. not sure why while didn't work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top