Can't timeline.push within a function? #2908
Answered
by
nikbpetrov
letitiayhho
asked this question in
Q&A
-
Due to the nested nature of my experimental design, it seems like the best way to create trials is with an explicit
for (let trial = 1; trial < n + 1; trial++) {
console.log({ trial });
timeline.push(make_trial(block_number, trial));
timeline.push(pause)
}
function make_block(block_number, trial, n) {
for (let trial = 1; trial < n + 1; trial++) {
console.log({ trial });
timeline.push(make_trial(block_number, trial));
timeline.push(pause)
}
}
timeline.push(make_block(block_number, trial, n))
timeline.push(pause) // this will not show up after make_block() |
Beta Was this translation helpful? Give feedback.
Answered by
nikbpetrov
Dec 20, 2022
Replies: 1 comment 1 reply
-
Calling the function in 2 should return a value - you do not return anything, instead you push to the timeline. Two options: function make_block(block_number, trial, n) {
temp_timeline = []
for (let trial = 1; trial < n + 1; trial++) {
console.log({ trial });
temp_timeline.push(make_trial(block_number, trial));
temp_timeline.push(pause)
}
// note that because this will be added to the main timeline later, this needs to be return like a timeline object, not array
return {timeline: temp_timeline}
}
timeline.push(make_block(block_number, trial, n))
timeline.push(pause) or function make_block(block_number, trial, n) {
for (let trial = 1; trial < n + 1; trial++) {
console.log({ trial });
timeline.push(make_trial(block_number, trial));
timeline.push(pause)
}
}
make_block(block_number, trial, n)
timeline.push(pause) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
letitiayhho
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Calling the function in 2 should return a value - you do not return anything, instead you push to the timeline.
Two options:
or