selector.shuffle

getSelector(id).shuffle() (since beta 0.3)

or getSelector(id).shuffle( element1 , element2 , ... )

Shuffles the elements that have been added to the selector so far, so their positions on the page are randomly switched (NB: make sure the elements are already printed when you call shuffle).

You can specify a subset of elements to be shifted, so the other elements will remain in their original position no matter what, if you do not want to shuffle them.

Note: if you call .keys before you shuffle, the key-element associations will be preserved. If you call .keys after you shuffle, each key will be associated with the element that ends up where the element it was originally associated with was (useful if for instance you assign a key to “the element on the left” and a key to “the element on the right”).

Example:

[js highlight=”10″ try=”true”]newImage(“square”, “square.png”)
,
newImage(“triangle”, “triangle.png”)
.settings.before( getImage(“square”) )
.print()
,
newSelector(“shapes”)
.settings.disableClicks()
.settings.add( getImage(“square”) , getImage(“triangle”) )
.shuffle()
.settings.keys( “F” , “J” )
.wait()[/js]

Adds two images side by side. Initially, square is on the left, and triangle is on the right, but .shuffle randomly reverses (or does not reverse) the order. A press on the F key will select the image that ends up on the left (whichever it ends up being) and a press on the J key will select the image that ends up on the right (whichever it ends up being).