This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes
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?

in Engine by (15 points)

2 Answers

+1 vote
Best answer

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: https://github.com/godotengine/godot/issues/18468. It's been fixed in the latest master and will be correct in 3.0.3.

by (346 points)
selected by
+1 vote

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()

by (116 points)
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 Frequently asked questions and 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 [email protected] with your username.