The whole engine doesnt respond after adding a new function to the code [Solved]

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

Im not sure what causes this but after I added the add_alternative_path() function to my tilemap code, the scene wont start and it will tell me that the engine doesnt respond anymore. No error or anything. Why?

Here is the function (I dont know if the rest of the code is needed but its really just this function that causes trouble also the rest is too long):

func add_alternative_paths():
var unvisited = []
var stack = []
var current = Vector2()
var first = true
var dominant_walls = 0
inbetween_space = 1

#put empty spaces to the unvisited array
for x in range(0, width, inbetween_space):
	for y in range(0, height, inbetween_space):
		if get_cellv(Vector2(x, y)) == 15:
			unvisited.append(Vector2(x, y))

#make the extrarooms
while unvisited.size() > 0:
	current = unvisited[randi() % unvisited.size()]
	while stack.size() > 0:
		var neighbors = check_neighbors(current, unvisited)
		if neighbors.size() > 0:
			if int(current.x) % 2 == 0 && int(current.y) % 2 == 0:
				dominant_walls = 56
				dominant_walls = 71
			var next = neighbors[randi() % neighbors.size()]
			var dir = next - current
			var current_walls = get_cellv(current) - cell_walls[dir]
			var next_walls = get_cellv(next) - cell_walls[-dir]
			set_cellv(current, current_walls + dominant_walls)
			set_cellv(next, next_walls + dominant_walls)
			current = next
			first = false
		elif stack:
			current = stack.pop_back()

Please help me with this one I have no idea what to do next

:bust_in_silhouette: Reply From: jgodfrey

I can only assume that one or more of those while loop end conditions aren’t working as you intend. I think the engine is getting caught in an infinite loop because it’s not exiting from one of the loops.

You could try to add some print statements in the loop(s). Or, probably better, set a debug break point in that function and step through the code line-by line until you find the problem.

I dont get how it doesnt end. What is the explanation for this. Both of these are going to run out of tile positions since it always removes one of them

Also how do debug breakpoints?

Snaper_XD | 2020-02-06 01:19

The problem is solved. Unvisited never erases its very first variable

Snaper_XD | 2020-02-06 01:43

For the sake of completeness (and because it’s really useful):

To set a breakpoint either…

  • Insert a line containing breakpointin your script


  • Click in the empty space to the left of the line numbers. A red dot will appear, indicating the change. Clicking it will remove the breakpoint again.

Now when you run your game and the breakpoint inside your script is reached, the game will pause and the debugger will open. Press F12 to continue running (until the next breakpoint is reached) or F10 / F11 to step through your script line by line. F11 will step into functions where possible, F10 will skip them over.

In case you forget these keys, there a buttons for all of them at the top right of the Debugger and menu entries in the “Debug”-menu of the Editor as well.

njamster | 2020-02-06 11:42

Thank you. The problem is solved now but I will try the breakpoint thing out for the next problem. The issue was btw that the first value in unvisited() never gets removed. Thank you for your help

Snaper_XD | 2020-02-06 16:49