while loop calling a function in either _process or _fixed_process

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By captainnimmo
:warning: Old Version Published before Godot 3 was released.

I am doing something similar to the “Navigation Polygon (2D)” example, except have more than one item to move along the path. As a result, I didn’t want to repeat the same while loop in _process twice and so wanted a separate function. All attempts wouldn’t work. One example is below:

func _process(delta):
	if (path.size() > 1):
		while(to_walk > 0 and path.size() >= 2):
            some_function()

I also tried a simple test with the while loop only in “some_function()” as well:

    func _process(delta):
    	if (path.size() > 1):
          some_function()

func some_function():
	while 1<2:
		print ("a never ending while")

Is there a way of doing this or a reason this can’t be done?

Are you sure you can’t just do for node in nodes_to_move, and put the while loop inside?

Bojidar Marinov | 2016-03-21 16:07

I think that would work too yes, thanks!

captainnimmo | 2016-03-21 17:12

:bust_in_silhouette: Reply From: captainnimmo

I found a solution - the separate function needs to return something, eg:

func _process(delta):
 if (path.size() > 1):
        while(to_walk > 0 and path.size() >= 2):
           someVariable =  some_function(someVariable)