# Function in a timer script

**URL:** <https://forum.inductiveautomation.com/t/function-in-a-timer-script/5366>\
**Category:** Ignition\
**Created:** [November 1, 2012, 4:20pm UTC](https://forum.inductiveautomation.com/t/function-in-a-timer-script/5366 "2012-11-01T16:20:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![njsd](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@njsd](https://forum.inductiveautomation.com/u/njsd)\
**Post date:** [November 1, 2012, 4:20pm UTC](https://forum.inductiveautomation.com/t/function-in-a-timer-script/5366/1 "2012-11-01T16:20:57Z")

</div>

Hello,

I can’t seem to get a function to work inside a timer script. I am trying to move an icon slowly from a location to a location further down the screen. I have the following script on a timer script set at 250ms. When I set it like this it works:

```auto
import system
PALLET_STOP = 700

window = system.gui.getWindow("Main Window")
pallet = window.rootContainer.getComponent("Image 4")
if pallet.y < PALLET_STOP:
	system.gui.moveComponent(pallet, pallet.x, pallet.y + 1)
elif pallet.y == PALLET_STOP:
	pass
else:
	print "Failed to move"
	
#def movePallet(pallet, stop)
#	window = system.gui.getWindow("Main Window")
#	pallet = window.rootContainer.getComponent("Image 4")
#	if pallet.y < stop:
# system.gui.moveComponent(pallet, pallet.x, pallet.y + 1)
#	elif pallet.y == stop:
# pass
#	else:
# print "Failed to move"

#movePallet(pallet_icon, PALLET_STOP)
```

But when I try to call the same code in a function it does not work:

```auto
import system
PALLET_STOP = 700

#window = system.gui.getWindow("Main Window")
#pallet = window.rootContainer.getComponent("Image 4")
#if pallet.y < PALLET_STOP:
#	system.gui.moveComponent(pallet, pallet.x, pallet.y + 1)
#elif pallet.y == PALLET_STOP:
#	pass
#else:
#	print "Failed to move"
	
def movePallet(pallet, stop):
	window = system.gui.getWindow("Main Window")
	pallet = window.rootContainer.getComponent("Image 4")
	if pallet.y < stop:
		system.gui.moveComponent(pallet, pallet.x, pallet.y + 1)
	elif pallet.y == stop:
		pass
	else:
		print "Failed to move"

movePallet(pallet_icon, PALLET_STOP)
```

Is there something wrong with my definition?

Thank you!

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [November 1, 2012, 6:49pm UTC](https://forum.inductiveautomation.com/t/function-in-a-timer-script/5366/2 "2012-11-01T18:49:25Z")

</div>

There’s a couple of things wrong with the second script, both of which would’ve thrown errors in the client console (client script) or wrapper log (gateway script). The variable pallet\_icon isn’t defined, and you need to import system into the def.

---

<div class="post-metadata">

**Author:** ![njsd](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@njsd](https://forum.inductiveautomation.com/u/njsd)\
**Post date:** [November 1, 2012, 7:21pm UTC](https://forum.inductiveautomation.com/t/function-in-a-timer-script/5366/3 "2012-11-01T19:21:28Z")

</div>

```auto
PALLET_STOP = 700

def movePallet(stop):
	import system
	
	window = system.gui.getWindow("Main Window")
	pallet = window.rootContainer.getComponent("Image 4")
	
	if pallet.y < stop:
		system.gui.moveComponent(pallet, pallet.x, pallet.y + 1)
	elif pallet.y == stop:
		pass
	else:
		print "Failed to move"

movePallet(PALLET_STOP)
```

worked. thanks!
