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)