Using timeline variables with the survey-likert plugin #2619
-
On each trial of my study, I'd like to present a likert prompt that changes according to the values inside a timeline variable. To provide a toy example: on trial one, I might ask how much participants like ice cream, and on trial two, how much they like veggies. Naively, I'd expect the following code to accomplish this. var test = {
timeline: [
{
type: jsPsychSurveyLikert,
questions: [
{
prompt: "How much do you like " + jsPsych.timelineVariable("test_prompt") + "?",
name: "like",
labels: ["Not at all", "Somewhat", "A great deal"]
},
{
prompt: "Is " + jsPsych.timelineVariable("test_prompt") + " your favorite food?",
name: "favorite",
labels: ["No", "Yes"]
}
],
}
],
timeline_variables: [
{ test_prompt: "ice cream" },
{ test_prompt: "veggies" }
]
} However, I am instead finding that the timeline variable seems to take on the value If anyone has pointers on how I might fix this, it'd be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @psychNerdJae, Because you are combining the timeline variable with other information you'll need to use a dynamic parameter. prompt: () => { return "How much do you like " + jsPsych.timelineVariable("test_prompt") + "?"; }, When you call Also, if you try this and it doesn't work, it might be because we haven't properly implemented support for nested parameters as timeline variables. I think we fixed this in a recent release, so I think it will work, but do follow up here if it doesn't before spending too much time trying to debug what might be our fault. |
Beta Was this translation helpful? Give feedback.
Hi @psychNerdJae,
Because you are combining the timeline variable with other information you'll need to use a dynamic parameter.
When you call
jsPsych.timelineVariable()
it actually returns a special kind of object, which jsPsych then treats like a dynamic parameter later on during the experiment run. So you are seeing[object Object]
because the value ofjsPsych.timelineVariable()
is this object. When you wrap the wholeprompt
parameter in a function, then the jsPsych engine will wait to evaluate this timelineVariable until runtime and it will return the value of the timeline variable at th…