How to get a var or use a func from its base class?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mateusak
:warning: Old Version Published before Godot 3 was released.

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

extends "res://Scripts/" 

func _ready():

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

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

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?

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. :slight_smile:

uheartbeast | 2016-04-22 21:05

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.

mateusak | 2016-04-22 21:55

Is in the same directory as If so you should be able to inherite like so:

extends ""

Does that make a difference?

uheartbeast | 2016-04-22 22:29

Absolutely none.

mateusak | 2016-04-22 22:31

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

uheartbeast | 2016-04-22 22:51

:bust_in_silhouette: Reply From: uheartbeast

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

extends Node2D

var name = "none"

func speak():

extends ""

func _ready():
	print("Say: " + name + " again.")

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

mateusak | 2016-04-22 23:01

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

uheartbeast | 2016-04-22 23:03

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?

mateusak | 2016-04-22 23:13

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.

uheartbeast | 2016-04-23 02:14

Okay, thanks anyway.

mateusak | 2016-04-23 14:00