change variable of an added child?

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

Via inspector I chose my enemy and depending on this choice, it will add the enemy as a child to the scene, this object has a kinematic body with a script attached to it with stats.

The question is, how do change variables in my match? Normally it would be like: $Object.value = 100 or something like that but that doesn’t work here, neither does enemy.speed = 100, instead I get an error: invalid set index ‘number’ (on base: ‘KinematicBody2D’) with value of type ‘int’

instance has a variable called speed, I get this error with every variable.

This is my whole setup:

    extends Node

enum ENEMIES {
	slime,
	goblin,
	mushroom,
	fly,
	worm	
}

export(ENEMIES) var enemies # = ENEMIES.goblin -> set default choice, if not, 
							#the first enemy in enum gets picked as default

var slime = preload("res://Scenes/Enemies/Slime.tscn")
var goblin = preload("res://Scenes/Enemies/Goblin.tscn")
var bat = preload("res://Scenes/Enemies/Fly.tscn")
var fungi = preload("res://Scenes/Enemies/Fungi.tscn")
var worm = preload("res://Scenes/Enemies/Worm.tscn")

func _ready():
		
	match enemies:
		ENEMIES.slime:
			var enemy = slime.instance()
			add_child(enemy)

		ENEMIES.goblin:
			var enemy = goblin.instance()
			add_child(enemy)

		ENEMIES.mushroom:
			var enemy = fungi.instance()
			add_child(enemy)

		ENEMIES.fly:
			var enemy = bat.instance()
			add_child(enemy)

		ENEMIES.worm:
			var enemy = worm.instance()
			add_child(enemy)
:bust_in_silhouette: Reply From: clemens.tolboom

Guess you need enemy outside _ready() too.

Checking with https://docs.godotengine.org/en/stable/classes/class_kinematicbody2d.html

Kinematic bodies are special types of bodies that are meant to be user-controlled.

You can move_and_slide them though.
This movement is done in func _physics_process

...
var enemy :KinematicBody2D
func _ready():
    match enemies:
        ENEMIES.slime:
        enemy = slime.instance()
        add_child(enemy)
...
func _physics_process(delta):
    #enemy.speed = 100
    enemy.move_and_slide(your settings)