0 votes

Im not sure what causes this but after I added the addalternativepath() 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()]
    stack.append(current)
    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
            else:
                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
            unvisited.erase(current)
            first = false
        elif stack:
            current = stack.pop_back()

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

in Engine by (12 points)
edited by

1 Answer

0 votes

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.

by (10,936 points)

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?

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

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

To set a breakpoint either...

  • Insert a line containing breakpointin your script

or

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.