0 votes

I need to tag more nodes in a time but it dont allow me that. But i don't want my code like this:

func off_off_ladder_checker():
$Off_Ladder_Block/CollisionShape2D.set_deferred("disabled", false)
$Off_Ladder_Block/CollisionShape2D2.set_deferred("disabled", false)
$Off_Ladder_Block/CollisionShape2D3.set_deferred("disabled", false)
$Off_Ladder_Block/CollisionShape2D4.set_deferred("disabled", false)
$Off_Ladder_Block/CollisionShape2D5.set_deferred("disabled", false)

I want it a little bit shorter without repeats.
Can someone help please?

Godot version 3.5
in Engine by (12 points)

1 Answer

0 votes

You could do

for node in $Off_Ladder_Block.get_children():
    node.set_deferred("disabled", false)

As a a general rule, any time you're repeating yourself a bunch of times, a loop is probably the solution.

by (21,716 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.