Add attribute to entity (Python)


#1

I wanted to add an attribute to Ship object to be able to track it throughout the game. Something like this:
self.destination = None
in the __init__ function.

But it seems that each turn it is initialised as if a new object was created. I.e., in the beginning of each turn, it’s None over and over.

Could you please help find the solution to this?


Values of objects not changing in list after modification - python
Can Ship ID change from frame to frame?
#2

Create dict like targets[ship.id]=position. It is the easiest solution.


#3

Thank you for the reply! That’s exactly how I do it now. But I’d still like to use attributes, if there’s a way.


#4

There are plans in the works for persistent ship instances between turns.

See here and here.

I wrote and have been using the _generate solution just fine.