Noob Question: Class creation in loop

Hi all,

I know this is a really stupid question and I am missing something on a fundamentally basic level, but I have been looking everywhere and tried multiple different ways of doing it until I gave up and came here in the hope of someone pointing me in the right direction.

So basicly I am trying to run a loop to create multiple classes namely Subclass1, Subclass2, Subclass3 etc.

for i = 1,5
do Subclass[i] = Myclass()

I have also tried feeding the name of the subclass into a table, and then running the table through the loop, as well as trying to run a different loop to create the names of the sublass and then feeding those names into the creation loop.

I would really appreciate anyone helping me to understand what I am doing wrong.

Why are you doing this? Do you need the classes to actually be different, with different functions? If not, then the issue is that your thinking might be flawed.

Are you really trying to make instances of a single class? If so, what you wrote should be fine; use the indexer to reference the classes.

If you really want subclasses, then you’d do:

for i=1,5 do
    Subclass[i] = class(Myclass)

I get it now, I knew it was something simple that I was missing. Thanks for the replies! :smiley: