I am trying to instantiate and add enemy scenes into the level by setting an array of String with references to the paths to the Scenes in the File System; each level should have different sets of enemies to instantiate at certain times. This is the code that should make this work, the func is called once in a _ready func.

I have tested this with a single var of type String that is also edited in the Inspector, and it worked, so I was wondering why the array in the Inspector always got an invalid result, an image of the Inspector for the Scene with the Level Loader.

And a picture of the error and relevant data.

Hopefully someone is able to help me and many others out here, and if so, I will appreciate it a lot!

  • Pretty sure your issue is that :

    for n in enemyArray:
    works such that n is each array element iterated over. Using n as the index into the array is the likely problem.
    Try:

    for n in range(0, len(enemyArray)):
    To get the number index as n

Pretty sure your issue is that :

for n in enemyArray:
works such that n is each array element iterated over. Using n as the index into the array is the likely problem.
Try:

for n in range(0, len(enemyArray)):
To get the number index as n

This worked like a charm!

Thank you very much, I was unaware of how "n in array" was actually a hindrance to how it indexed the array itself; you are right, better to use range and len(array).