0 votes

I'm learning Godot using Godot Engine Game development projects and I came across this code that bugs me. It's from chapter 4 "Space Rocks". I am instancing a scene called rock in the main scene using export (Packed scene). The rock scene has a code to explode when the player shoot it

I connected an exploded signal in the main scene

   func spawn_rock(size, pos=null, vel=null
            var r = Rock.instance()
             #Rocks is a child note of the main scene
             #I'm using Rocks node as a container for the rock scene
              r.connect("exploded", self, "on_Rock_exploded")

Then connected the function _on_Rock_exploded
The _on_Rock_exploded was suppose to explode the rock and split it into two but when I run it doesn't happen. And then debugger showed this emit_signal: Error calling method from signal 'exploded': 'Node(Main.gd)::on_Rock_exploded': Method not found
I tried everything but it always show that error. I don't know what to. Please Help
The code for the onRock_exploded is below

  func _on_Rock_exploded(size, radius, pos, vel):
            if size <= 1: 
            for offset in [-1,1]:
                  var dir = (pos - $Player.position).normalized().tangent() * offset
                  var newpos = pos + dir * radius
                  var newvel = dir * vel.length() * 1.1
                  spawn_rock(size -1, newpos, newvel)
in Projects by (14 points)

1 Answer

0 votes

Godot is telling you it cannot find 'Node(Main.gd)::on_Rock_exploded':, because:

r.connect("exploded", self, "on_Rock_exploded")

You missed a _ at the beginning of the function name.

by (27,170 points)

Thank for the help.
The debugger issue was solved but the split into two rocks issue is still happening. There are no errors but when I run the game and shoot the rocks it just explodes instead of exploding and splitting into two

You may have to put a breakpoint in _on_Rock_exploded(size, radius, pos, vel) and see what are the argument values. Perhaps it's receiving the wrong size?

I checked func _on_Rock_exploded() function and all codes inside it and matched it with the codes on the book and found no mistake. I am suspecting that it has to do with animation_finished() signal
I have a animation_finished() signal connected in Rock scene's script

func _on_AnimationPlayer_animation_finished(anim_name):

I think the problem is because of thequeue_free() but I am not sure.

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.