and I was working with class RowOfAtoms objects row_000, row_001, …
Everything worked fine!
Then I decided to make a list of gameobjects and a list of RowOfAtoms class
objectlist = []
rowsofatoms = []
for o in sce.objects:
if 'Row' in o.name: # If you find an object with starting with 'Row'
objectlist.append(o) # Add the object reference to the list
rowsofatoms.append(RowOfAtoms.RowOfAtoms(o))
print(objectlist) # Print out the list of objects
print gives correct object list of [‘Row’, ‘Row.001’, … etc]
The problem is that this line
rowsofatoms.append(RowOfAtoms.RowOfAtoms(o))
gives errors. I mean I do not understand why appending the class instance based on the gameobject does not work!
class RowOfAtom(bge.types.KX_GameObject):
def __init__(self, object):
...
When you then wrap an object with this wrapper, the old gameobject reference will be destroyed.
Say you do:
a = scene.objects.get(...)
b = Wrapper(a)
# this will crash, because BGE freed the object stored in "a":
a.worldPosition
On the other hand, the object could also simply be removed, but the reference still exists inside your variables/lists, but they are marked as “invalid” and will raise exceptions when you try to use them.
Basically it is raising an error on the line with the print(list) because the references have been invalidated as I told you,
And because print will try to fetch the name of each object in the list, but BGE will say “nope, I freed that, you cannot get the name”.