0 votes

Hi all,

Working on game 4. The arkanoid / breakout clone.

I have a "Gun Bat" and it works well, UNTIL the bullet object hits the last brick object. I then get the following error:

Invalid call. Nonexistent function 'get_nodes_in_group' in base 'KinematicBody2D (bullet.gd)'.

Here is the code leading up to that point in the bullet script:

#find out if we hit a brick
if is_colliding():
    var entity = get_collider()
    if entity.get_parent().is_in_group("bricks"):
        #destroy the brick
        entity.get_parent().destroyThisBrick()
        #destroy ourselves
        queue_free()
        #check if the level is over or not (we shot the last brick)
        if get_tree().get_nodes_in_group("bricks").size() <= 1:
            #show the congrats scene
            get_node("/root/gameLevel/levelFinished").showScene()
            get_node("/root/gameLevel/levelFinished").updateLabels()
            #remove any leftover balls
            ###################################################
#THIS IS THE BUG, BELOW, FOR SHOOTING THE LAST BRICK AND IT FAILING
            ###################################################
            if self.is_inside_tree():
                if get_tree().get_nodes_in_group("balls").size() >= 1:
                    var ballList = get_nodes_in_group("balls")
                    #/\  Above is the line it errors on  /\
                    for i in ballList:
                        i.queue_free()

I'm a little confused on this. Any advice would be very much appreciated.

in Engine by (810 points)

1 Answer

+1 vote
Best answer

get_nodes_in_group() is a method of SceneTree. You use it correctly the first time, but the second time, you're trying to call it on the script object, which is a 'KinematicBody2D'.
Change to this:

if get_tree().get_nodes_in_group("balls").size() >= 1:
                var ballList = get_tree().get_nodes_in_group("balls")

or you could change it to:

var ballList = get_tree().get_nodes_in_group("balls")
if ballList.size() >= 1:
by (18,221 points)
selected by

...buries face into hands and sighs

Thank you. It's so obvious now I read it. It's almost embarasing. BUT, I very much appreciate your help. I've been at this for days and just didn't see it.

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