# Calling a function issue

**URL:** <https://forum.inductiveautomation.com/t/calling-a-function-issue/8760>\
**Category:** Ignition\
**Created:** [July 20, 2014, 11:49pm UTC](https://forum.inductiveautomation.com/t/calling-a-function-issue/8760 "2014-07-20T23:49:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![oxanemi](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@oxanemi](https://forum.inductiveautomation.com/u/oxanemi)\
**Post date:** [July 20, 2014, 11:49pm UTC](https://forum.inductiveautomation.com/t/calling-a-function-issue/8760/1 "2014-07-20T23:49:37Z")

</div>

I have a gateway script which basically checks three tags (Fault, Acknowledge, AcknowledgeCounter). I had no problems running the script and it worked perfectly.

```auto
PLC_ACK = system.tag.read("PLC Heartbeats/Test/Ack")
PLC_AckCounter = system.tag.read("PLC Heartbeats/Test/AckCounter")
PLC_Fault = system.tag.read("PLC Heartbeats/Test/Fault")

if PLC_Fault.value == 1:
	if PLC_ACK.value == 1 and PLC_AckCounter.value < 179: ##changes every 3 hrs
		count = PLC_AckCounter.value + 1
		system.tag.write("PLC Heartbeats/Test/AckCounter",count)

	elif PLC_ACK.value == 1 and PLC_AckCounter.value == 179: ##changes every 3 hrs
		value = 0
		system.tag.write("PLC Heartbeats/Test/AckCounter",value)
		system.tag.write("PLC Heartbeats/Test/Ack",value)

	elif PLC_ACK.value == 0:
		system.tag.write("PLC Heartbeats/Test/AckCounter",0)

elif PLC_Fault.value == 0:
	system.tag.write("PLC Heartbeats/Test/AckCounter",0)
	system.tag.write("PLC Heartbeats/Test/Ack",0)
```

The above code deals with one device (Test). I need to implement this for multiple devices. Hence, I tried to wrap this code in a function and then call out the function but to no avail.

Here’s what I tried to do

```auto
def tagFunction(AckTag,AckCounterTag,FaultTag):
	import system
	
	PLC_Ack = system.tag.read(AckTag) 
	PLC_AckCounter = system.tag.read(AckCounterTag)
	PLC_Fault= system.tag.read(FaultTag)

	if PLC_Fault.value == 1:
		if PLC_Ack.value == 1 and PLC_AckCounter.value <180:
			count = PLC_AckCounter.value + 1
			system.tag.write(PLC_AckCounter,count)
			
	
		elif PLC_Ack.value == 1 and PLC_AckCounter.value == 180:
			value = 0
			system.tag.write(PLC_Ack,value)
			system.tag.write(PLC_AckCounter,value)		
	
		elif PLC_Ack.value == 0:
			system.tag.write(PLC_AckCounter,0)
	
	elif PLC_Fault.value == 0: ## if PLC_Fault == 0
		system.tag.write(PLC_Ack,0)
		system.tag.write(PLC_AckCounter,0)
		
tagFunction("PLC Heartbeats/Test/Ack","PLC Heartbeats/Test/AckCounter","PLC Heartbeats/Test/Fault")
##tagFunction("PLC Heartbeats/CMP2VC/Ack","PLC Heartbeats/CMP2VC/AckCounter","PLC Heartbeats/CMP2VC/Fault")
```

I am new to programming so I presumed this is the correct way to implement it. Is it an issue with the format with which I am providing the arguments?

Thank You!

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 21, 2014, 9:12am UTC](https://forum.inductiveautomation.com/t/calling-a-function-issue/8760/2 "2014-07-21T09:12:45Z")

</div>

This seems fine. What is the problem? Do you see any exceptions in the “Status -\> Gateway Scripts” Gateway webpage?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 21, 2014, 3:33pm UTC](https://forum.inductiveautomation.com/t/calling-a-function-issue/8760/3 "2014-07-21T15:33:03Z")

</div>

I don’t see anything obviously out of place on first blush either.

One thing I do see is the possibility of PLC\_AckCounter.value being greater than 180. consider changing it to:

```auto
elif PLC_Ack.value == 1 and PLC_AckCounter.value >= 180:
```

That will help ensure a reset, even if it accidentally goes above your reset point.

---

<div class="post-metadata">

**Author:** ![oxanemi](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@oxanemi](https://forum.inductiveautomation.com/u/oxanemi)\
**Post date:** [July 21, 2014, 3:54pm UTC](https://forum.inductiveautomation.com/t/calling-a-function-issue/8760/4 "2014-07-21T15:54:38Z")

</div>

> [@nmudge](#):
>
> This seems fine. What is the problem? Do you see any exceptions in the "Status -\> Gateway Scripts" Gateway webpage?

It works fine now! I had forgotten the "import system" step in the actual gateway script! Turned out to be quite a silly thing in the end!! Thanks for helping me troubleshoot and find the actual fault!

---

<div class="post-metadata">

**Author:** ![oxanemi](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@oxanemi](https://forum.inductiveautomation.com/u/oxanemi)\
**Post date:** [July 21, 2014, 3:55pm UTC](https://forum.inductiveautomation.com/t/calling-a-function-issue/8760/5 "2014-07-21T15:55:03Z")

</div>

[quote=“JordanCClark”]I don’t see anything obviously out of place on first blush either.

One thing I do see is the possibility of PLC\_AckCounter.value being greater than 180. consider changing it to:

```auto
elif PLC_Ack.value == 1 and PLC_AckCounter.value >= 180:
```

That will help ensure a reset, even if it accidentally goes above your reset point.[/quote]

Yes, I have changed it! Thank You!
