# Calling custom methods

**URL:** <https://forum.inductiveautomation.com/t/calling-custom-methods/13955>\
**Category:** Ignition\
**Created:** [March 30, 2017, 10:32pm UTC](https://forum.inductiveautomation.com/t/calling-custom-methods/13955 "2017-03-30T22:32:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [March 30, 2017, 10:32pm UTC](https://forum.inductiveautomation.com/t/calling-custom-methods/13955/1 "2017-03-30T22:32:33Z")

</div>

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](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:

> [@](#):
>
> NameError: global name 'event' is not defined

This just doesnt make sense.. ![:scratch:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/76d1620bec252bfac07050c889ff5a91dc8a9c25.gif ":scratch:")  
Any ideas?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 31, 2017, 12:23am UTC](https://forum.inductiveautomation.com/t/calling-custom-methods/13955/2 "2017-03-31T00:23:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![richardNZ15](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/richardnz15/32/33373_2.png) [@richardNZ15](https://forum.inductiveautomation.com/u/richardNZ15)\
**Post date:** [March 31, 2017, 1:10am UTC](https://forum.inductiveautomation.com/t/calling-custom-methods/13955/3 "2017-03-31T01:10:57Z")

</div>

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

`event.source.Updating = 0`Which 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 = 0`and now everything is executing fine.

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