Error "Division by zero in operator '..'.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By patrick03
var paths = []
const path_dir="res://Paths"

func _ready():
	loadPaths()
	pass

func random_path():
	return paths[randi()% paths.size()]
	pass

func loadPaths():
	var dir = Directory.new()
	dir.change_dir(path_dir)
	dir.list_dir_begin()
	var files =dir.get_next()

	
	while files!="":
		var path = load(path_dir+ files)
		if path && caminho is Curve2D:	
			paths.append(caminho)
		file =dir.get_next()
	pass

What I’m doing wrong?

:bust_in_silhouette: Reply From: mrLogan

I am not familiar with your code but shouldn’t it be files rather than file in the second last line i.e files = dir.get_next()

:bust_in_silhouette: Reply From: jandrewlong

If the error is pointing at return paths[randi()% paths.size()], the problem is that you are trying to modulo paths.size() which is zero.

If you’re using 3.0.2, there was a problem with the operators reported by that error. I reported it here: Wrong operator reported on type mismatch · Issue #18468 · godotengine/godot · GitHub. It’s been fixed in the latest master and will be correct in 3.0.3.