Created
April 27, 2021 09:23
-
-
Save jakewilliami/ceed3307704251b97cc2dbde8e213a91 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function takeFirst<T>(arr: T[]) { | |
const firstVal: T = arr[0]; | |
arr.splice(0, 1); | |
return firstVal; | |
} | |
SM.addState(State.SubTrial, { | |
onEnter: (machine: stateMachine.Machine, blockStruct: BlockStruct) => { | |
if (blockStruct.trialArrayURLs.length === 0) { | |
// then we need to initialise another trial! | |
machine.transition(State.Response, blockStruct); | |
} else { | |
// then we need to start, or are still, looping through the trial array | |
// choose the first, or next, image from the trial array | |
const thistrial: string = utils.takeFirst(blockStruct.trialArrayURLs); | |
gorilla.populate('#gorilla', 'subtrial', {thistrial: thistrial}); | |
$('#gorilla') | |
.queue(function () { | |
$('.trial-image').show(); | |
gorilla.refreshLayout(); | |
$(this).dequeue(); | |
}) // end queue for '#gorilla' | |
.delay(imageDisplayLength) | |
.queue(function () { | |
// this queue isn't strictly necessary, as we loop through the SubTrial state, replacing the trial image | |
$('.trial-image').hide(); | |
gorilla.refreshLayout(); | |
$(this).dequeue(); | |
}) // end queue for '#gorilla' | |
.queue(function () { | |
// once again, must be inside the queue or it will not display | |
machine.transition(State.SubTrial, blockStruct); | |
$(this).dequeue(); | |
}) // end queue for '#gorilla' | |
} // end if | |
} // end onEnter | |
}) // end addState State.SubTrial |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment