However, I never could work out how to do that because I cant
apply your decorators like @taskmethod to the
def __call__(self, *args, **kargs)
In the end I just provide an Action method to all my objects.
When constructing the behaviour trees I do something like
owyl.sequence( SpokenResponse().Action(), ..)
which isn't as nice as just passing callables.
If you can think of a way of passing and callables instead of just
functions and methods
that maybe a nice feature.
Thanks
> --
> You received this message because you are subscribed to the Google Groups "Owyl-discuss" group.
> To post to this group, send email to owyl-d...@googlegroups.com.
> To unsubscribe from this group, send email to owyl-discuss...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/owyl-discuss?hl=en.
>
>
Ah Thanks
I should have noticed wrap. Sorry
class SpokenResponse(object):
def __init_(self):
super(SpokenResponse, self).__init__()
self.__name__ = "SpokenResponse"
def __call__(self, *args, **kwargs):
yield self.Action(*args, **kwargs)
@owyl.taskmethod
def Action(self, *args, **kwargs):
print "Spoken Response"
yield True
instance = SpokenResponse()
tree = owyl.sequence(
owyl.task(instance)(),
owyl.task(instance)(),
owyl.task(instance)(),
owyl.fail()
)
v = owyl.visit(tree)
[x for x in v]
I get
line 59, in task
initTask.__name__ = func.__name__
AttributeError: 'SpokenResponse' object has no attribute '__name__'
I guessing my callables have to have __name__ and __doc__ defined.
But that didn't seem to help above.
> You could probably do something cutesy and declarative with a
> metaclass or class decorator, come to think of it, but I'll leave that
> as an exercise to the reader.
>
> However, this doesn't get you any closer to easy serialization. In
> fact, serializing a tree that you build in Python would probably be
> the hardest way to go, because you really don't have good
> introspection into nested active generators, which is what an owyl
> tree is built out of. It might be possible, but you might end up
> having to hack Python's C interface to do it. Just speculating here--
> I'm way beyond my knowledge on this.
>
> Even then, you still have the problem of deserialization, which is
> what I was talking about previously. This is a much more tractable
> problem. So long as your XML schema (or whatever) is rich enough to
> describe tree nodes, arguments, and children, you can construct a tree
> out of it without much sweat.
>
> Again, I hope that's helpful.
>
Thanks David. That does all make sense, fortunately I only need deserialisation.
And thanks for the code.
From the test following I get the error.
child = current.next()
AttributeError: 'function' object has no attribute 'next'
I tried experimenting with wrap versus task etc with no luck.
Have you any ideas ?
Thanks.
class SpokenResponse(object):
def __init_(self):
super(SpokenResponse, self).__init__()
@property
def __name__(self):
return self.__class__.__name__
def __call__(self, *args, **kwargs):
return self.Action(*args, **kwargs)
@owyl.taskmethod
def Action(self, *args, **kwargs):
print "Spoken Response"
yield True
instance = SpokenResponse()
tree = owyl.sequence(
owyl.task(instance)(),
owyl.task(instance)(),
owyl.fail()
)
v = owyl.visit(tree)
[x for x in v]