jspsych-canvas-button-response function from inside a plugin #2013
-
Hi everyone, I'm making a modification of jspsych-canvas-button-response plugin and I'm wondered if it's possible to include a drawing function from inside the plugin into the function that stimulus receive. For example: function filledCirc(canvas, radius, color){
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(250, 250, radius, 0, 2 * Math.PI);
ctx.fillStyle = color;
ctx.fill()
}
var circle_1 = {
type: 'canvas-button-response',
stimulus: function (c) {
filledCirc(c, 100, 'blue');
},
choices: ['Red', 'Green', 'Blue'],
prompt: '<p>What color is the circle?</p>',
data: {color: 'blue', radius: 100}
}; In this case I would like to insert the function filledCirc inside my plugin. When I try to do that I have the following error: Thank you! Best, Gustavo. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @GEJ1! Just to clarify: you're defining the var circle_1 = {
type: 'canvas-button-response-filledCirc',
stimulus: function(c) {
filledCirc(c, 100, 'blue'
}
// etc.
}; In this case I would expect that you'd get the "filledCirc is not defined" error because the functions contained in the plugin file are not accessible from the HTML file (even when called inside of a dynamic parameter). If your trials always need to use the var circle_1 = {
type: 'canvas-button-response-filledCirc',
radius: 100, // parameter for filledCirc
color: 'blue', // parameter for filledCirc
choices: ['Red', 'Green', 'Blue'],
prompt: '<p>What color is the circle?</p>'
}; Then in the plugin file, you can define the //draw
let c = document.getElementById("jspsych-canvas-stimulus")
filledCirc(c, trial.color, trial.radius); // canvas object c is defined by the plugin, but color and radius come from parameters Does that make sense, and does it help with what you're trying to do? |
Beta Was this translation helpful? Give feedback.
Hi @GEJ1! Just to clarify: you're defining the
filledCirc
function in the plugin file, but your trial definition in the HTML references that function name, like this:In this case I would expect that you'd get the "filledCirc is not defined" error because the functions contained in the plugin file are not accessible from the HTML file (even when called inside of a dynamic parameter). If your trials always need to use the
filledCirc
function, then you should just be able to use that function in the plugin file without calling it anywhere in the …