Topic was automatically imported from the old Question2Answer platform.
Asked By
Scavex
I want to use value of a variable in another variable. For example let’s say that I have a variable enemyNumber = 1 and then I have another variable enemy.
Now is there any way I can join these two together ? I want enemy1. Is something like that even possible ?
If I understand you right I think an array is what you need.
var enemies = []
func _ready():
var enemy = load("<enemy_scene_file>").instance()
enemies.append(enemy)
Now you have you enemy object in an array and you can append as many more as you like. You call them or set their position for example: enemy[0].global_transform.origin = Vector3(10, 0, 10) or whatever. size(enemies) will give the count of objs.
That’s doing it with objects mind. It’s usually better t0 handle pointers to the actual objects stored neatly in an array rather than abstract int and str variables about them buried throughout your code but it’s up to you.