I have a class called character
extends Node2D
var id
var selected
var health
var damage
func init(pos, health, damage, texture,id):
self.position = pos
self.health = health
self.damage = damage
self.get_node("Sprite").texture = load("res://assets/sprites/"+texture+".png")
self.id = id```
which i want to add multiple of in a scene. My solution so far is to have in the main scene
```py
func _ready():
characters.append(add_character(Vector2(500,500),100, 20, "blue", 0))
characters.append(add_character(Vector2(700,500),70, 30, "red", 1))
...
func add_character(pos, health, damage, texture, id):
var CharacterScene = load("res://scenes/character.tscn")
# Create an instance of the Character scene
var character_instance = CharacterScene.instantiate()
# Set properties of the Character instance
character_instance.init(pos, health, damage, texture, id)
# Add the Character instance to the scene tree
add_child(character_instance)
return character_instance
is there a better way to do this?