Include file, heritage and interfaces

TomLaPommeTomLaPomme Posts: 19Member
edited September 16 in Programming

Hello everyone !

I use GDscript for coding and I'm trying to implement this kind of architecture :

First, I want my "" can access (but not modify) the dictionnary contains in "".
And then, I want to create three other KinematicBody2D which inherits from This way, I don't have to write again moving functions and player and clones move thogether in the same time. My questions are "is each scene a class callable by it name ?", "is there a way to implement interface or access to variable of another script?", "how can I make heritage?"
This is my severals script :
const param = {
    "WEIGHT" : 5,
    "SPEED"  : 200,
    "JUMP_HEIGHT" : -200,
    "JUMP_NB" : 2

And in this script I wanna use param dictionary instead of declare several constants.
I don't declared it in because, I want parameter can be modify but not Character objects.
extends KinematicBody2D
var motion = Vector2();
const WEIGHT = 5;
const SPEED = 200;
const JUMP_HEIGHT = -200;
const JUMP_NB = 2;
const UP = Vector2(0,-1);
func _physics_process(delta): 
    motion.y += WEIGHT;
    if is_on_floor() : JUMP_NB =2;
    if Input.is_action_pressed("ctrl_right"):motion.x =SPEED; 
    elif Input.is_action_pressed("ctrl_left"):motion.x =-SPEED;
    else : motion.x = 0;
    if Input.is_action_pressed("ctrl_jump") and JUMP_NB !=0:
        if is_on_floor() or is_on_wall() :
            motion.y =JUMP_HEIGHT; 
    motion = move_and_slide(motion,UP);

and then coding Clone_1 and Clone_2 extends both KinematicBody2D and

Tags :


  • ZenzorZenzor Posts: 6Member
    edited September 16

    extending a class, you won't need to instantiate, just call your code
    extends ""
    func _init():
    SPEED = 100

    and call your other class instantiating it

    var myclass = preload("") 
    func _init(): 

    If you want extends both KinematicBody2D and, i reccomend you do your extending and your parameters class extends KinematicBody2D

Sign In or Register to comment.