title: Sikuli: How to get program to capture part of the screen and store as image
body: <p>So I want to capture one image, image s, which is always in the same region. It then disappears and may or may not re-appear in a different region. </p>
  
  <p>I would like the program to capture the first time it appears and if it re-appears in the other region, then click a set of buttons otherwise move to a different function.</p>
  
  <p>The other thing is image s changes each time the function is called but it remains in the same location.</p>
  
  <p>Below is my code:</p>
  
  <pre><code>def playLoop():
  
  s = capture(firstRegion)
  warnBox = exists("1443867801301.png")
  if not warnBox:
      if exists("1443867813008.png"):
          click(x)
          playLoop()
      else:
          if secondRegion.exists(Pattern(s).similar(0.8)):
              wait(3)
              click(x)
              playLoop()
          else:
              loopLoop()
  else:
      doubleClick(y)
      if secondRegion.exists(Pattern(s).similar(0.8)):
              wait(3)
              click(x)
              playLoop()
      else:            
          loopLoop()
  </code></pre>
  
  <p>I get no errors, however it doesn't seem to work. Any ideas?</p>