How do I refine my code in Sikuli? Seems very long and redundant I'm only just beginning in programming. 

The goal of the program is to check to make sure images are properly rendered within a program(within a VM)

. Below is the code, and I am asking what I can do to clean it up.

I don't think you can tell much without the .png's, but I would appreciate it if anyone knows where/how I can optimize my code.

Thank you very much for any help,

var=(0) #Empty Variable
jpgl=0 #NUMBER PASSES
vm = App("C:\Program Files (x86)\VMware\VMware Workstation\\vmware.exe")
switchApp("vm")
reg=( )
reg.find( )
#------------------------------------
#BEGINNING SPECIAL CASES/NAVIGATION
if not exists( ):
    switchApp("vm")
    type(Key.BACKSPACE)
    onAppear( ,type(Key.BACKSPACE))
if exists( ):
    click( )
#if exists( ):#attempt to get rid of.
#   click( )
else:
    exists( )
    click( )
    exists( )
    click( )
    wait(1)
    if not exists ( ):#if the image hasn't already loaded, wait the maximum 5 seconds
        wait(5)
#END FOLDER NAVIGATION
#----------------------------------
#BEGIN IMAGE CHECK 1
    if not exists ( ):
        print("B-JPEG_L-20.jpg not displayed correctly")
    if exists( ):
        print("B-JPEG_L-20.jpg Unable to play")
        click( )
    else:
        jpgl=jpgl+1#if the image exists, it moves on by clicking "next"
        click( )
        wait(1)
        if not exists ( ):
            wait(5)
#DONE IMAGE CHECK 1
#----------------------------------
#BEGIN IMAGE CHECK 2
.....

#end code
One way to get started improving your script is to find repeated code, then create a function to hold it.

For example, if your code starting with #BEGIN IMAGE CHECK 1 is duplicated for subsequent image checks, it could become a function that takes a Sikuli image file name - define it somewhere near the top of your file (NOTE: This assumes the same image filename is used consistently across this entire chunk of code, which may not be true in your unedited code):

def check_image(image_filename):
        if not exists(image_filename):
                print("%s not displayed correctly" % image_filename)
        if exists(image_filename):
                print("%s Unable to play" % image_filename)
                click(image_filename)
        else:                  
                jpgl = jpgl + 1                                                 
                click(image_filename)
                wait(1)        
                if not exists (image_filename):
                        wait(5) 


Then below that you can call the function with:

check_image('foo.jpg')


Then you should have a starting point for incrementally refining your code. At some point creating a class to hold your test logic could be useful as well.

I recommend reading up on functions and classes in Python - solid knowledge in those areas really helps out with Sikuli development:

http://docs.python.org/tutorial/controlflow.html#defining-functions

http://docs.python.org/tutorial/classes.html#tut-classes