My code:
onready var planet = preload("res://Planet.tscn")
var planet_sizes = [0.15, 0.25, 0.35]
var created_planets = []
var goodtoadd = true
func _ready():
randomize()
draw_planets()
func draw_planets():
while created_planets.size() < 2:
var planet_coords = Vector2(rand_range(50, 1870), rand_range(50, 1030))
if not planet_coords in created_planets: #if there is not already a planet at those coordinates
if len(created_planets) == 0: #if there are no planets
goodtoadd = true
else:
for existing in created_planets: # if planet is further than 35 pixels from all other planets
if planet_coords.distance_to(existing) < 35:
goodtoadd = false
if goodtoadd:
var s = planet.instance()
add_child(s)
s.position = planet_coords
var size = planet_sizes[int(rand_range(0, 3))]
s.set_scale(Vector2(size, size))
created_planets.append(planet_coords)
The while loop is completing, and when created_planets.size() equals 2, it deletes everything in there and runs again. And when the size equals 2 again, it stops. And for some reason, changing the 2 to anything higher than 3, causes the test window to crash. I need the number to be 40 or so.