using the value of dynamic variable to determine whether a timeline event should occur or not #2751
Unanswered
IngridYu0211
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Hi @IngridYu0211, if I understand correctly then I think what you want to do is put the trial inside of a conditional node. The conditional node has a function that runs right before the trial should run, so inside the conditional function, you want to check the value of your variable and use that to decide whether to run the timeline (trial) or not. So for example, if you have a variable called var count = 0; // this variable tracks the number of certain trials
var trial = {
// trial parameters...
}
var conditional_node = {
timeline: [trial],
conditional_function: function() {
if (count == 5) {
return false; // skip the trial
} else {
return true; // run the trial
}
}
}
// put the conditional node on the main timeline, rather than the trial itself
timeline.push(conditional_node); I hope this helps! Let us know if you have more questions. And feel free to post your code if you're still running into problems. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'd like to ask how to use the value of a dynamic variable on the current trial to determine whether that trial should be executed or not. The dynamic variable is set at 0 at the start then increases by 1 at the repetition of certain trials. I tried using get data from last trial function and giving that to the value of this dynamic variable but it didn't work. Is there a way to index like say variable X(trial)? I'm very new to jsPsych, sorry if this sounds silly!
Beta Was this translation helpful? Give feedback.
All reactions