Wednesday, June 18, 2025

The For Loop in GDScript (Or: Why I'm Gonna Hit Someone)

So I can write a for loop in other languages. I am aware that this makes me a member of an exclusive club called Everybody. But, like, look! See?

As you can tell from that thick, luscious error message, that ain't it chief. Sooooo, maybe:

But I don't want it to be a node. I want it to be an int. Apparently in GDScript, if you're writing a for loop, the for (variable) is always gonna be a node. Always and forever.

I didn't get a screenshot, but apparently the right answer is:

for i in button_container.get_children():
if i.disabled == false:
i.grab_focus()

But like with tabs that Blogger doesn't eat.

So of course, I immediately stepped on a rake and NEEDED i to be typed. Do you know how to do it?

Other sane languages would let you do i : whatever, but gdscript, you're typing that bad boy inside the loop.

Thanks! I hate it!

1 comment:

  1. In the second example does it work to rename "i" to "child" then inside the for loop just use child.disabled and child.grab_focus() or am I missing something/the point?

    ReplyDelete