0 votes

This question might be stupid, but this is the first game I'm making and I really need some help.
I'm trying to make a puzzle game for connecting pipes. I put all of the needed buttons in array and when I run this program I get this on Debugger: Invalid get index '0' (on base: 'null instance')
And on errors: get_node: (Node not found: "arg" (relative to "/root/Node2D/Button").)

extends Button

var i=0
var arg=[]

func ready():
while(i < 76):
var button = Button.new()
$arg[i].connect("pressed", self, "myrotate")
func myrotate():

in Engine by (24 points)

1 Answer

+1 vote
Best answer

No need for the $
And you forget to update iwhich is why for is better for this kinda thing

extends Button

var arg=[]

func ready():
    for i in range(arg.size()):
        var button = Button.new()
        button.connect("pressed", self, "myrotate", [i])
        arg.insert(i, button)

func myrotate(i):
by (6,876 points)
selected by

Thank you so much. I've been working on this problem for 2 days and it finally works.

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.