Repeat

Asked by charliedaps

Hello,

I know it's totally stupid but I can not do repeat.

Here is my code.

I would like it to be repeated 200 times.

click(1006,748)
click("1551707620478.png")
type(Key.ENTER)
type('c', KeyModifier.CTRL)
click("1551704040161.png")
type('v', KeyModifier.CTRL)
sleep (2)
if(exists("1551704943136.png")):
    click(613,587)
    type('a', KeyModifier.CTRL)
    type(Key.DELETE)
    click("1551707221495.png")
else:
   click("1551703683676.png")
   find("1551706524071.png")
   click("1551706538103.png")

I add

for i in range(200):

on the first line but i have a error.

Thanks for your help

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
charliedaps (charliedaps) said :
#1

I have read this link

https://answers.launchpad.net/sikuli/+faq/1437

but i don't understeend

I have this message

[error] script [ hope ] stopped with error in line 2 at column 0
[error] SyntaxError ( "mismatched input 'click' expecting INDENT", )

Thanks

Revision history for this message
RaiMan (raimund-hocke) said :
#2

you have to understand python indentation!
faq 1800 might help

Revision history for this message
Rainer (formulator) said :
#3

You have to indent the whole code within the "for" block, in the same way as you do with the "if" block.

This is a quite basic Python question by the way, and has nothing to do with SikuliX

Revision history for this message
charliedaps (charliedaps) said :
#4

Thanks for your quickly anwser.

for i in range(200):
click(1006,748)
click("1551707620478.png")
type(Key.ENTER)
type('c', KeyModifier.CTRL)
click("1551704040161.png")
type('v', KeyModifier.CTRL)
sleep (2)
if(exists("1551704943136.png")):
    click(613,587)
    type('a', KeyModifier.CTRL)
    type(Key.DELETE)
    click("1551707221495.png")
else:
   click("1551703683676.png")
   find("1551706524071.png")
   click("1551706538103.png")

I do that

I understood that it was the base but all the explanations that I find seem so complicated.

What is my mistake in this code?

thank you in advance

Revision history for this message
Rainer (formulator) said :
#5

Your code should look like this:

for i in range(200):
      click(1006,748)
      click("1551707620478.png")
      type(Key.ENTER)
      type('c', KeyModifier.CTRL)
      click("1551704040161.png")
      type('v', KeyModifier.CTRL)
      sleep (2)
      if(exists("1551704943136.png")):
          click(613,587)
          type('a', KeyModifier.CTRL)
          type(Key.DELETE)
          click("1551707221495.png")
      else:
         click("1551703683676.png")
         find("1551706524071.png")
         click("1551706538103.png")

The whole code in the "for" block (everything that you want to be executed repeatedly) needs to be indented (moved to the right) by one level.

Revision history for this message
charliedaps (charliedaps) said :
#6

Thank you very much for this explanation.

Indeed, I did not find this information. While I applied it for the else.

One more question, it does not work.

He does not start the loop again.

He does it only once.

Thank you

Revision history for this message
Rainer (formulator) said :
#7

The following code:

for i in range(4):
    print(i)
    if i % 2:
        print("is odd")
    else:
        print("is even")

should result in the following output:

0
is even
1
is odd
2
is even
3
is odd

Could you please copy & paste this code in the SikuliX IDE and run it? Does it work?

Revision history for this message
charliedaps (charliedaps) said :
#8

Thanks for your help

Yes it works.

I have the same result.

Revision history for this message
Rainer (formulator) said :
#9

This structure is identical to your structure.

Now you can start "populating" this barebone structure with your code, line by line, and run it after each addition. So you should be able to determine the line(s) that give you problems.

Revision history for this message
charliedaps (charliedaps) said :
#10

A big thanks.

Everythink is OK.

Have a good day.

Can you help with this problem?

Provide an answer of your own, or ask charliedaps for more information if necessary.

To post a message you must log in.