Python property classes support a mechanism to transparently treat python class attributes as cel properties, this means any property you set on the map or elsewhere (like quests) will directly translate to a python attribute change in your instance.

Python property classes support a mechanism to transparently treat python class attributes as cel properties, this means any property you set on the map or elsewhere (like quests) will directly translate to a python attribute change in your instance.

-

You can override SetProperty to intercept property setting from the outside and react appropriately on your code. Otherwise you have to assume your property can be changed anytime from the outside (which may work good for many uses).

+

You can definer a python getter and setter for your property as usual. Otherwise you have to assume your property can be changed anytime from the outside (which may work good for many uses).

A Simple Python Property Class

Where "pchelloworld" would be the actual name to use when creating such a property class.

Knowing when the entity has been set

You thought property classes live inside entities? False! Initially they are created on component nirvana, and (usually) after that they get assigned to an
entity, and you get a SetEntity call in your property class. Note this can happen more times, but you don't need to support it (but you might).

Usually you will use the call to SetEntity to register with its message channel, or create further property classes on it.

from pycel import*class HelloWorldExtended(pyPcCommon):
def__init__(self,oreg):
pyPcCommon.__init__(self,oreg)def SetEntity(self,entity):
# dont forget to call common behaviour or you'll get in trouble.
pyPcCommon.SetEntity(self,entity)print"assigned to entity:",entity.Name
CEL_IMPLEMENT_FACTORY(HelloWorldExtended,"pchelloworld2")

Registering time events with the physical layer

All python property classes implement a cel timer listener, this means they can register with the physical layer to get time ticks. The following example should illustrate sufficiently:

from pycel import*class RotatePropClass(pyPcCommon):
def__init__(self,oreg):
pyPcCommon.__init__(self,oreg)# register for tick events
PhysicalLayer.CallbackEveryFrame(self,CEL_EVENT_PRE)# register to be called back when 1 second has passed
PhysicalLayer.CallbackOnce(self,1000,CEL_EVENT_PRE)def TickEveryFrame(self):
# this gets called before every frame gets drawn in response# to CallbackEveryFrame registering.
mov = celMesh(self.GetEntity()).Mesh.GetMovable()
rot = csYRotMatrix3(0.1)
mov.Transform(rot)
mov.UpdateMove()def TickOnce(self):
# this gets called after the requested time has passed in# response to CallbackOnce.print"One second has passed!"
CEL_IMPLEMENT_FACTORY(RotatePropClass,"pcrotate")

Sending Messages

the first form is more efficient when we will send the same message many times, while the second is good for casual sending of messages.

Properties

Python property classes support a mechanism to transparently treat python class attributes as cel properties, this means any property you set on the map or elsewhere (like quests) will directly translate to a python attribute change in your instance.

You can definer a python getter and setter for your property as usual. Otherwise you have to assume your property can be changed anytime from the outside (which may work good for many uses).