Create functions and call them whenever needed

Asked by Jeff Sant

I want to create functions and reuse them whenever needed, and i also want nested functions.

e.g

myFunction():
 click here
 click there
 if any error call myError()

myError()
 popup("error occured")
 exit()

/// main program

click this
call myFunction()

if error call myError()

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

If you want to do more complex things in Sikuli script, you have to learn some Python basics.

recommended source: http://jythonpodcast.hostjava.net/jythonbook/en/1.0/

your question:

def myFunction():
 click here
 click there
 if any error call myError()

def myError():
 popup("error occured")
 exit()

/// main program

click this
myFunction()

if error: myError()

functions can have parameters (guess you know ;-)

and you can pack all your function stuff into a separate myfunctions.sikuli and import it in all your scripts
using
from myfunctions.sikuli import *
read: http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images

Revision history for this message
Jeff Sant (sant-jeff) said :
#2

Thanks RaiMan, that solved my question.