# Drag drop to random (pre-defined) location

Not getting any errors, but also not doing anything. Trying to move an image to a randomly defined coordinate:

import random
from random import choice

def position1():
position1 = Location(548,292)

def position2():
position2 = Location(633,293)

def position3():
position3 = Location(738,288)

def position4():
position4 = Location(817,284)

def randomDrop():
positionOneToFour = [position1, position2, position3, position4]
random.choice(positionOneToFour)()

def main():
dragDrop("1573618403777.png",(randomDrop))
print('done')

main()

## Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
2019-11-13
Last query:
2019-11-13
2019-11-13
 xyz_User (userseven) said on 2019-11-13: #1

@RainMan would really appreciate if you can provide some guidance :)
Thanks

 TestMechanic (ndinev) said on 2019-11-13: #2

You need to fix script like that ( I test it with hover but you can run it with your drag-drop)

import random
from random import choice

def position1():
return Location(548,292)

def position2():
return Location(633,293)

def position3():
return Location(738,288)

def position4():
return Location(817,284)

def randomDrop():
positionOneToFour = [position1(), position2(), position3(), position4()]
return random.choice(positionOneToFour)

def main():
hover(randomDrop())
print('done')

main()

 Manfred Hampl (m-hampl) said on 2019-11-13: #4

Have you tried

dragDrop("1573618403777.png",randomDrop()).

(note the position of the left parenthesis)

 TestMechanic (ndinev) said on 2019-11-13: #5

You are calling method incorrectly - you need
1. use () in functions call
2. use return

I example that i gave you i added ()
hover(randomDrop())

so you need to type randomDrop() instead of randomDrop in your dragDrop call

 TestMechanic (ndinev) said on 2019-11-13: #6

You need to fix script like that ( I test it with hover but you can run it with your drag-drop)

import random
from random import choice

def position1():
return Location(548,292)

def position2():
return Location(633,293)

def position3():
return Location(738,288)

def position4():
return Location(817,284)

def randomDrop():
positionOneToFour = [position1(), position2(), position3(), position4()]
return random.choice(positionOneToFour)

def main():
dragDrop("1573618403777.png",randomDrop())
print('done')

main()

 xyz_User (userseven) said on 2019-11-13: #7

Thanks Manfred Hampl, that solved my question.

 xyz_User (userseven) said on 2019-11-13: #8

Thanks guys - Got me to think and I solved it by storing the location objects in a list then using randint method from random to call the list.

Thanks again!

 TestMechanic (ndinev) said on 2019-11-13: #9

Thanks Manfred for solving the problem...