why does this not work?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lalel345

I want to make a loop so that when the area collides it changes position immediately where no collisions

while get_overlapping_areas():
    		self.global_position.x += 1

how could i do it then?

:bust_in_silhouette: Reply From: Magso

while is conditional meaning it needs a bool true or false value but get_overlapping_areas() returns an array. The array type has the size() method which returns an int so an operator (<, >) can be used to return a bool.

while get_overlapping_areas().size() > 0:

but it still doesn’t work

while get_overlapping_areas().size() > 0:
		position.x += 1

lalel345 | 2021-02-11 21:34

In the question, by ‘when the area collides’ did you mean with only other areas? If not you should be using get_overlapping_bodies() if you want to detect static, rigid & kinematicbodies.

Magso | 2021-02-11 23:59

while get_overlapping_areas().size() > 0:

will cause an endless-loop (game stops working) if size is not 0.

whiteshampoo | 2021-02-12 08:10

:bust_in_silhouette: Reply From: whiteshampoo
for _i in get_overlapping_areas():
    global_position += 1

or better:

global_position.x += get_overlapping_areas().size()

(both untested)