How can I access built in functions in a inherited script

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Adrian

So…
I have a KB2D root node Scene called “Character.tscn”, with a Script also called “Character.gd”

Then I have an inherited Scene (from Character.tscn) called “Player.tscn”, with a Script that inherits from “Character.gd”, called “Player.gd”

CHARACTER:

extends KinematicBody2D

const VELOCIDAD = 10
const VELOCIDAD_MAXIMA = 200
const FRICCION = 0.1

PLAYER:

extends “res://Personaje.gd”

func _process(delta):
pass

So far so good,BUT…
When I try to use for example move_and_slide in Player.gd, GDScript doesn´t recognize it, as if it weren´t part of the built in methods. oddly enough it CAN print the variables assigned in the original script, so it seem to be inheriting just fine.

My question is: Do I need to do something else in order to get the kinematic functions, even if both scenes are KB2D?

I´ve seen some tutorials, but they don´t do anything else, besides setting the extend on line 1.
Seems something to simple to fail, yet it does. I´m using GODOT 3.1.1 by the way.

I’m struggling with the same problem, i can’t move_and_slide from an inherited scene; can you explain how did you arranged your node tree?, what tutorial did you see that implemented this way of handling movement? any help would be great, thanks.

lofi | 2021-01-29 14:00

:bust_in_silhouette: Reply From: null_digital

I’m assuming “res://Personaje.gd” has the Character class.

Weird, PLAYER should have move_and_slide. Could you run the code with PLAYER calling move_and_slide and post the errors?

Also, I’d like to suggest using class_name to tidy up a bit.

new_script_1.gd

extends KinematicBody2D
class_name NewScript1

new_script_2.gd

extends NewScript1
class_name NewScript2

Hey thanks for the advice and the swift response!

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

var movimiento = Vector2()
 

func _process(delta):
	actualizar_velocidad(delta)
	move_and_slide(movimiento)


func actualizar_velocidad(delta):
	
	if Input.is_action_pressed("Arriba") and not Input.is_action_pressed("Abajo"):
		movimiento.y = clamp((movimiento.y -VELOCIDAD) , -VELOCIDAD_MAXIMA ,0)
		
	elif Input.is_action_pressed("Abajo") and not Input.is_action_pressed("Arriba"):
		movimiento.y = clamp((movimiento.y +VELOCIDAD) , 0 , VELOCIDAD_MAXIMA)
	else :
		movimiento.y = lerp(movimiento.y, 0, FRICCION)
	
	if Input.is_action_pressed("Izquierda") and not Input.is_action_pressed("Derecha"):
		movimiento.x = clamp((movimiento.x -VELOCIDAD) , -VELOCIDAD_MAXIMA ,0)
		
	elif Input.is_action_pressed("Derecha") and not Input.is_action_pressed("Izquierda"):
		movimiento.x = clamp((movimiento.x +VELOCIDAD) , 0 , VELOCIDAD_MAXIMA)
	else :
		movimiento.x = lerp(movimiento.x, 0, FRICCION)

Now i have actually tried it and it seem to work just fine, BUT the auto-complete keeps on suggesting methods for something else instead of KB2D:

master
mastersync
match
max(
min(
MARGINBOTTOM
movileVRinterface
ResourceFormatLoaderNativeScript
ResourceFormatLoaderVideoStreamGDNative

no move _and_slide sugestion for example, even if it can run.
Why is this happening? is there anything I can do to fix it?

Adrian | 2020-01-12 22:29

Those are Godot’s global stuff. They’ll be suggested in any gdscript.

@GDScript — Godot Engine (3.1) documentation in English

Can’t think of why your editor refuses to show move_and_slide. I’m using Godot 3.1.2.

null_digital | 2020-01-14 00:11

You´re right, I suspected that much. I´ll see if updating it fixes anything.

It´s probably my rig, It has another bug in the project management screen were the UI redraws itself one input delayed… kinda hard to explain, but I read somewhere that´s a common bug on some W10 versions.
Damn Windows.

Adrian | 2020-01-14 22:35

:bust_in_silhouette: Reply From: Adrian

FIXED
just update to V 3.1.2 !!