This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

Think Monster extends Creature.
Creature has the variable Speed and the function getforwardvector().

Monster.gd:

extends "res://Scripts/Creature.gd" 

func _ready():
    set_fixed_process(true)

func _fixed_process(delta):
    var Sa = get_forward_vector() 
    #gives the error "Invalid call. Nonexistent function 
    'get_forward_vector' in base 'KinematicBody2D (Ɓspher.gd)'."

    var Sp = Speed
    #gives the error "Parser Error: Identifier not found: Speed"

Creature.gd:

extends KinematicBody2D

export var Speed = 150

var Direction = 0

func get_forward_vector():
    if (Direction == 0):
        return Vector2(0, 1)
    elif (Direction == 1):
        return Vector2(-1, 0)
    elif (Direction == 2):
        return Vector2(0, -1)
    elif (Direction == 3):
        return Vector2(1, 0)

How can I get/use those? I tried simply putting them in and it didn't work. Can you make an example?

in Engine by (1,124 points)
edited by

We may need to see your code. You should be able to access both Speed and CalculateDirection() in the subclass without doing anything special as long as your inheritance is working correctly.

[edit] Although you should know that code completion doesn't appear to work. If there is a way to get it to work I don't know how, yet. :)

I know it, but it gives me an error. Gonna edit it, and include the scripts. Although I don't think it'll make any difference.

Is Monster.gd in the same directory as Creature.gd? If so you should be able to inherite like so:

extends "Creature.gd"

Does that make a difference?

Absolutely none.

I made an example project and added it as an answer. It works fine for me. Does it work for you?

1 Answer

+1 vote
Best answer

Okay, I've made an example project. Here is the code and also a link to the bitbucket repository with the entire project.

Bitbucket: Project Source

creature.gd

extends Node2D

var name = "none"

func speak():
    print(name)

monster.gd

extends "creature.gd"

func _ready():
    speak()
    print("Say: " + name + " again.")
by (103 points)
selected by

Well, I excluded and remade it and now it works. Thanks :)

Glad it works now. That is strange that it wasn't working in the other project.

Can you answer one more thing? How to know when two kinematics are colliding? Like if I use get_collider() it returns the Object. So there's a way to do something like self.Object to get your own object?

Hmm, I might not actually be the best person to answer that one. I've only been using Godot for about 2 weeks and I've only messed around with the Area2D collisions. Sorry about that.

Okay, thanks anyway.

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.