0 votes

Hi I get the message "Parser Error: Identifier not found: bird" for my project which prevents the game from running. I have used the identifier bird in other places and it works perfectly but for some reason it is not being recognized when I used it to create the flap(): function which is located inside of the #FlappingState. I troubleshooted for hours but I can't figure out what I did wrong.

I am using version v2.15.stable official (The tutorial I am following is not compatible to 3.0). Here is the link to the tutorial I am following with the timestamp:
https://youtu.be/y2HBgjNxS4s?list=PLv3l-oZCXaql20IlPe7gfBEzomnPSLekY&t=519

Thanks for your help!

# birdscript
extends RigidBody2D

onready var state = FlappingState.new(self)

func _ready():
    set_process_input(true)
    set_fixed_process(true)
    pass

func _fixed_process(delta):
    state.update(delta)
    pass



func _Input(event):
    state.Input(event) 
    pass

# Flying State -----------------------------------------------------------------------------------------
class FlyingState:


func _init():
    pass

func update(delta):
    pass

func input(event):
    pass 


func exit():
    pass

# Flapping State -----------------------------------------------------------------------------------------
class FlappingState:
    var bird

func _init(bird):
    self.bird = bird 


    bird.set_linear_velocity(Vector2(50, bird.get_linear_velocity().y))
    pass

func update(delta):
    if rad2deg(bird.get_rot()) > 30:
        bird.set_rot(deg2rad(30))
    bird.set_angular_velocity(0)

    if bird.get_linear_velocity().y > 0:
        bird.set_angular_velocity(1.5)
    pass

func input(event):
    if event.is_action_pressed("flap"):
        flap()
        pass 


func flap():
    bird.set_linear_velocity(Vector2(bird.get_linear_velocity().x, -150))
    bird.set_angular_velocity(-3)
    pass

func exit():
        pass


# HitState State -----------------------------------------------------------------------------------------
class HitState:


func _init():
    pass

func update(delta):
    pass

func input(event):
    pass 


func exit():
    pass

# Ground State -----------------------------------------------------------------------------------------
class GroundState:


func _init():
    pass

func update(delta):
    pass

func input(event):
    pass 


func exit():
    pass
asked Feb 24 in Engine by NoobishDev (12 points)

You didn't say on what line you're getting the error.

The errors were on line 64-67.The indentation got rid of the error and the scene now runs. (Thank you for that. solution). However the bird does not flap like it did before I reformatted the code. My code looked like this before it was reformatted and it worked perfectly it looked just like this:
https://youtu.be/y2HBgjNxS4s?list=PLv3l-oZCXaql20IlPe7gfBEzomnPSLekY&t=266

Here is my new code. There is no error messages it is simply not allowing me to control the bird like I was able to before. Instead the bird just falls to the ground.

# birdscript
extends RigidBody2D

onready var state = FlappingState.new(self)

func _ready():
    set_process_input(true)
    set_fixed_process(true)
    pass

func _fixed_process(delta):
    state.update(delta)
    pass



func _Input(event):
    state.Input(event) 
    pass

    # Flying State -----------------------------------------------------------------------------------------
class FlyingState:


    func _init():
        pass

    func update(delta):
        pass

    func input(event):
        pass 


    func exit():
        pass

# Flapping State -----------------------------------------------------------------------------------------
class FlappingState:
    var bird

    func _init(bird):
        self.bird = bird 


        bird.set_linear_velocity(Vector2(50, bird.get_linear_velocity().y))
        pass

    func update(delta):
        if rad2deg(bird.get_rot()) > 30:
            bird.set_rot(deg2rad(30))
        bird.set_angular_velocity(0)

        if bird.get_linear_velocity().y > 0:
            bird.set_angular_velocity(1.5)
        pass

    func input(event):
        if event.is_action_pressed("flap"):
            flap()
        pass 


    func flap():
        bird.set_linear_velocity(Vector2(bird.get_linear_velocity().x, -150))
        bird.set_angular_velocity(-3)
        pass

    func exit():
        pass

# HitState State -----------------------------------------------------------------------------------------
class HitState:


    func _init():
        pass

    func update(delta):
        pass

    func input(event):
        pass 


    func exit():
        pass

# Ground State -----------------------------------------------------------------------------------------
class GroundState:


    func _init():
        pass

    func update(delta):
        pass

    func input(event):
        pass 


    func exit():
        pass

Try renaming the main class function _Input to _input. I'm pretty sure function names are case-sensitive.

Thank you so much SIsilicon! That worked. I must have done that trying to "fix" something else. Have a great day!

Glad I could help. I converted my comment to an answer.

1 Answer

0 votes

I noticed that your inner classes' functions don't have indentation. The parser probably mistook their functions for the main class's own, which indeed doesn't have bird defined.

answered Feb 24 by SIsilicon (3,513 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 How to use this Q&A? before posting your first questions.