Function in a timer script

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:

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:

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!

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.

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!