Calling custom method from message handler of the same item

Could a custom method be called directly from a message handler of the same item?

I'm trying but it doesn't work.

How are you trying to call it? Post some code.

def onMessageReceived(self, payload):

	self.methodOfTheItem()

In the same way, if I call a method of some of the children, the method is not found. Does it have to be a method implemented within the the child "instance"?

ie.

	def onMessageReceived(self, payload):

		item = self.getChild('theItemName')
		item.methodOfTheItem()

What do you mean by that?

Calling self.methodOfTheItem() should work if the custom method methodOfTheItem() is defined on the same component that the message handler is defined on.

Basicly, this is the sketch:

In MHReset(), if I print the type of the method to be called:

type(self.reset)

the result is "<type 'instancemethod'>", and just later, the calling ("self.reset()") fails.

This should work as expected. Make sure the scope is properly configured, both in the sendMessage call and in the message handler.

If they are, something else is going wrong and you'll need to add logs to find out what.

1 Like