Calling custom methods

I am having some fustration with trying to call custom methods on a button component.
I've looked at the manual and various other forum posts.

https://docs.inductiveautomation.com/display/DOC/Component+Custom+Methods

Creating a simple custom method on a button "printMessage()", that prints "Hello World" to the console works if i call it with: event.source.printMessage()

But when i try and write a more complex custom method, and call it in the same manner, it doesnt work.event.source.methodName()
And Ignition throws up the error:

This just doesnt make sense.. :scratch:
Any ideas?

1 Like

The custom method itself doesn’t have access to the event variable itself. It can only use properties and methods of ‘self’ and whatever you might pass it as parameters. { ‘self’ inside the method is event.source as you’ve shown it. } Custom methods can be called by scripts outside the event system, or by project or shared scripts that don’t have the event either, so the infrastructure is general. The same as any class object in python, actually.

Ah yes, so the error I was getting was actually complaining about having the following code in my custom method:

event.source.Updating = 0Which was setting a custom property of the button to 0.

I thought the error from Ignition was referring to the following code in the Event Handler script:

event.source.methodCall() but it was really complaining about the code inside my Custom Method.

I have since changed the offending line in my custom method code to:

self.Updating = 0and now everything is executing fine.

Goes to show it pays to play close attention to the exact line the error is thrown at!

1 Like