Groups Code Example

1 view
Skip to first unread message

Jay Herrmann

unread,
Apr 27, 2010, 10:33:16 PM4/27/10
to pysage
Hi,

I recently found the pysage project. I am excited to use it on
project. I have reviewed the wiki and docs. But I am unable to get
the groups example code to work in my sample app. Could someone put
together a simple example (with groups) like: https://code.google.com/p/pysage/wiki/SimpleUsage

An Example I thought would demonstrative this would be python code
something like this: (Note: I am new to python, but have used other
languages like C, Php, C++, Object Pascal. I tried a was not able to
get the following to work.)

import time
from pysage import Actor, ActorManager, Message

mgr = ActorManager.get_singleton()

class MainGroupMessage(Message):
TenSecCount=0
ThreeSecCount=0
properties = ['TenSecCount','ThreeSecCount']
packet_type = 101

class ThreeSecGroupMessage(Message):
properties = ['']
packet_type = 102

class TenSecGroupMessage(Message):
properties = ['']
packet_type = 103

class MainAction(Actor):
subscriptions = ['MainGroupMessage']
def handle_MainGroupMessage(self, msg):
if msg.get_property('TenSecCount')!= self.TenSecCount:
self.TenSecCount=msg.get_property('TenSecCount')
if msg.get_property('ThreeSecCount')!= self.ThreeSecCount:
self.ThreeSecCount=msg.get_property('ThreeSecCount')
print 'Ten Second Count %s -- Three Second Count %s' %
[self.TenSecCount,self.ThreeSecCount]

class ThreeSecAction(Actor):
Count=0
startTime = time.time()
subscriptions = ['ThreeSecGroupGroupMessage']
def handle_ThreeSecGroupMessage(self, msg):
self.Count=self.Count+1
mgr.queue_message_to_group(mgr.PYSAGE_MAIN_GROUP,
MainGroupMessage(ThreeSecCount=self.Count))
def update(self):
if time.time() - self.startTime >= 3.0:
mgr.queue_message(ThreeSecGroupMessage())
self.startTime=time.time()

class TenSecAction(Actor):
Count=0
startTime = time.time()
subscriptions = ['TenSecGroupMessage']
def handle_TenSecGroupMessage(self, msg):
self.Count=self.Count+1
mgr.queue_message_to_group(mgr.PYSAGE_MAIN_GROUP,
MainGroupMessage(TenSecCount=self.Count))
def update(self):
if time.time() - self.startTime >= 10.0:
mgr.queue_message(TenSecGroupMessage())
self.startTime=time.time()

mgr.register_actor(MainAction())
mgr.add_process_group('ThreeSecGroup',ThreeSecAction)
mgr.add_process_group('TenSecGroup',TenSecAction)

while True:
processed = mgr.tick()
time.sleep(.03)

As I said before, I am still learning Python. So I may be my
incorrect programming. If so, is my use of the groups correct?

Thanks,
Jay

--
You received this message because you are subscribed to the Google Groups "pysage" group.
To post to this group, send email to pys...@googlegroups.com.
To unsubscribe from this group, send email to pysage+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pysage?hl=en.

Reply all
Reply to author
Forward
0 new messages