Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | mateusak | |
Old Version | Published before Godot 3 was released. |
Think Monster extends Creature.
Creature has the variable Speed and the function get_forward_vector().
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?
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.
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 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?
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