0 votes

Good day everyone!

For some reason I can find a solution for my problem and yet I think it's something simple but can't find in the Godot docs. The tutorial I'm following is written during the Godot 2 I assume so I've been learning Godot and the new docs at the same time. For some reason I get an error saying ':' expected at end of line. Yet I clearly have a colon there. Here is my code.

# script: bird

extends RigidBody2D

onready var state = FlappingState.new(self)

const STATE_FLYING   = 0
const STATE_FLAPPING = 1
const STATE_HIT      = 2
const STATE_GROUNDED = 3

func _ready():

    pass

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

func _input(event):
    state.input(event)
    pass

func set_state(new_state):
    state.exit()

    if new_state == STATE_FLYING: 
        state = FlyingState.new(self)
    elif new_state == STATE_FLAPPING:
        state = FlappingState.new(self)
    elif new_state == STATE_HIT:
        state = HitState.new(self)
    elif new_state == STATE_GROUNDED:
        state = GroundedState.new(self)
    pass

func get_state():

    if state extends FlyingState: #myproblem is here
        return  STATE_FLYING
    elif state extends FlappingState:
        return STATE_FLAPPING 
    pass
# class FlyingState --------------------------------------------------------------

class FlyingState:
    var bird

    func _init(bird):
        self.bird = bird

    func update(delta):
        pass

    func input(event):
        pass

    func exit():
        pass

# class FlappingState --------------------------------------------------------------

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_rotation()) < -30:
            bird.set_rotation(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("ui_spacebar"):
            flap()
        pass

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

    func exit():
        pass

# class HitState --------------------------------------------------------------

class HitState:
    var bird

    func _init(bird):
        self.bird = bird

    func update(delta):
        pass

    func input(event):
        pass

    func exit():
        pass

# class GroundedState --------------------------------------------------------------

class GroundedState:
    var bird

    func _init(bird):
        self.bird = bird

    func update(delta):
        pass

    func input(event):
        pass

    func exit():
        pass
in Engine by (23 points)

1 Answer

+2 votes
Best answer

if state extends FlyingState: is used and valid syntax before 3.0

after 3.0, it should be if state is FlyingState:

by (9,674 points)
selected by

Ahh thank you so much!

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.