how to select two images from different lists

Asked by morph

Hello!

How do i select pictures from 2 different lists. But not just select it should select the first picture of the first list and the first picture of the second list at the same time. At the next loop it should select the second item of the first list and the second item of the second list. I hope you understand what i mean. Here is my code.

item1=picture
item2=picture
item3=picture
itemA=picture
itemB=picture
itemC=picture
list=(item1,item2,item3)

for entry in list:
     if exists(entry)
         click(entry)
         do some code
#HERE i want to do a second "if" to select itemA,itemB,itemC but with the combination item1+itemA, item2+itemB and item3+itemC.

for context: i have a Game. With some Characters. I want to do something with each Character from the list. The Problem is on the Login the unselected Characters are blue and the selected one is Yellow and i work with:
click(Pattern(image).similiar(0.95))
Because the Names of the Characters are very similar. So Sikuli makes a difference between the two Versions of the Character.

I hope you understand my Problem.

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
Eugene S (shragovich) said :
#1

Hi,

First of all, you have a couple of problems in your example code:
1. You can't create a list with name 'list' as that's a reserved word
2. In Python a list is defined by '[]' rather that '()'. When you use '()', you will create a tuple.

I'm not sure I understood your question completely but to choose items from 2 lists in an orderly manner you can follow several approaches. For example:

lst1 = [item1,item2,item3]
lst2 = [item4,item5,item6]

OPTION 1:

for item in lst1:
   itemOne = item
   itemTwo = lst2.index(item) #This will return n item from lst2 location at the same location itemOne located in lst1

OPTION 2:

counter = 0

for item in lst1:
   itemOne = lst1[counter]
   itemTwo = lst2[counter]
   counter += 1

OPTION 3:

while (lst.__len__() > 0):
   itemOne = lst1.pop(0)
   itemTwo = lst2.pop(0)

And more...

NOTE: For all above cases, the assumption is that you have the same number of items in both lists.

Cheers,
Eugene

Revision history for this message
morph (lacrima-cruenta) said :
#2

ok so i worked with a tuple. Was working too ;-)
So i changed my example. Yes, the name was never List but thanks for the advise!
I need to use the "while" because i must know if it was clicked and disapeared before i go to the next action. A normal "while exists..." would be to fast and generates errors. This way i can control the speed and get some more things done.
I have the same Number of items. As i said its a list of characters selected and unselected.

NGlist=[item1,item2,item3,item4,item5,item6,item7,item8,item9]
AGlist=[itemA,itemB,itemC,itemD,itemE,itemF,itemG,itemH,itemI]
for entry in NGlist:
    entryOne = entry
    entryTwo = AGlist.index(entry)
    i=0
    while i<1:
        if exists(entryOne) or exists(entryTwo):
            if exists(entryOne):
                doubleClick(entryOne)
            if exists(entryTwo):
                doubleClick(entryTwo)
            wait(Pattern("Play.png").similar(0.95),120)
            i=1
        else:
            click("1408049363621.png")
            i=0

Thank you very much for your help! I hope that solved my Problem!

Revision history for this message
Eugene S (shragovich) said :
#3

-- need to use the "while" because i must know if it was clicked and disapeared before i go to the next action. A normal "while exists..." would be to fast and generates errors.

Not sure what you mean by that. What's a normal while?
Generally, if you must be sure that something happened as a result of your action (for example as a result of a click), you have two options:

1. Use timeout
2. Wait until the expected condition met. For example, if your click is going to trigger an appearance of a new figure on the screen, just wait until you have this figure and only then proceed.

Can you help with this problem?

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

To post a message you must log in.