sikuli-driver team mailing list archive
-
sikuli-driver team
-
Mailing list archive
-
Message #04063
Re: [Question #165533]: Can we have sections of codes and can jump while execution?
Question #165533 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/165533
Status: Open => Answered
RaiMan proposed the following answer:
you seem to already know, that Sikuli script "talks" Python language.
So we do not have a "goto".
the available elements to control the workflow of your script:
if/elif/else - make decisions (no case construct available)
while/for - loop as long a condition is met, or for a sequence of elements (look faq)
def - make functions that can be called from elsewhere
try/execpt - catch and handle exceptions
these are the most common ones.
in your case:
#generate random section to execute
import random
random.seed()
section_to_execute = random.randint(1, 3)
#now here is the code of all sections (before any section is run)
if section_to_execute == 1:
#section1
popup("you are in section 1 code")
elif section_to_execute == 2:
#section2
popup("you are in section 2 code")
elif section_to_execute == 3:
#section3
popup("you are in section 3 code")
else:
# this should not happen in your case
popup("something went totally wrong")
#now here is the code of all sections (after one of the sections was
run).
Mind indentation: use one tab for one indent level and use shift-tab for
dedent (works on blocks of selected lines).
--
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.