0 votes

So I having this error "Division By Zero in operator '%'", my intention is to get the quantity of children nodes and using them as a parameter to randi

extends Node
func create_meteor(value):
    return get_children()[value].duplicate()
func random_meteor():
    return get_children()[randi()%get_children().size()].duplicate()
in Engine by (15 points)

It's implying that get_children().size() is equal to 0. Does this node have children attached?

thank you for, your reply

Nodes

1 Answer

0 votes
Best answer

Try checking the stack trace when you receive the error, it might point you to where the random_meteor() function is being called where get_children().size() is returning 0.
Are you instancing this scene via code in another scene at all? If you are, you should make sure that random_meteor() is called after you add the scene to the tree (via add_child() in the other script). I'm not 100% sure but that's where I would look next.

by (506 points)
selected by
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.

Categories