Before you get into implementing this, what exactly is the pattern you're trying to make with this?
How complicated it gets comes down to whether one set of objects, both, or neither, will be changing (i.e. adding more or deleting some) throughout the pattern. If you have one set of objects where they just maybe move around without leaving the screen and the other is a bunch of bullets that are fired and then deleted, then that's easier than having two different sets of bullets where both of them are very dynamic and changing all the time.
In any case, here's the general outline for something like this:
function ObjectA(){
let objA = ObjSomething_Create();
// initialize objA
task DoStuffA(objA){
while(!Obj_IsDeleted(objA)){
// running object behaviour
yield;
}
}
DoStuffA(objA);
return objA;
}
function ObjectB(){
let objB = ObjSomething_Create();
// initialize objB
task DoStuffB(objB){
while(!Obj_IsDeleted(objB)){
// running object behaviour
yield;
}
}
DoStuffB(objB);
return objB;
}
let objA1 = ObjectA(); // makes an A object and puts its object ID into this variable
let objB1 = ObjectB(); // makes a B object and puts its object ID into this variable
// do things with both objA1 and objB1
If you have multiple instances of objA and objB (which is likely) you would make an array for each and add to the array for new objects, like
let listA = [];
let listB = [];
loop(m){
listA = listA ~ [ObjectA()];
}
loop(n){
listB = listB ~ [ObjectB()];
}
And then work with those arrays. However when you might want to add and delete stuff from the arrays a lot, that's where things get complicated, which is why it's important to know if your problem can be simplified somewhat (which is pretty likely).