Replies: 3 comments 4 replies
-
i now I can always declare them in my HTML (with the rest of JS), but I would like to pack everything together in my plugin :) |
Beta Was this translation helpful? Give feedback.
-
Hi @kernel52, I think the way that you do this will depend on what exactly you want to do. For instance, if you have a function that you want to be called when the expeirment loads, then you could either define that function in your main script or in a separate .js file that you load in the |
Beta Was this translation helpful? Give feedback.
-
@kernel52, ah, sorry for misunderstanding your question! I think I see what you mean now. Any custom functions that you want to use would typically be written into the plugin.trial function, and because plugins are self-contained, these functions are only available during that trial. But if you want to include functions with your plugin that are available throughout the whole experiment, then you're right that you'd need to ask users to load a separate file along with the plugin file in the head section. Some plugins have dependencies, e.g. virtual-chinrest, so asking the researcher to load an extra file alongside your plugin wouldn't be too unusual. I'm curious about why your plugin needs to include functions that are used outside of the plugin itself. If you want your plugin to be able to modify or extend the behavior of other plugins, then you could consider using jsPsych's new extensions feature. Extensions can be used 'on top' of other plugins and would allow you to declare functions that are available throughout the whole experiment. For an example, these functions are available throughout the experiment when the WebGazer extension is used. The functions are declared in the jspsych-ext-webgazer.js file, which is in the extensions folder. However, this extensions option may not make sense for what you're trying to do. I hope this helps! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I was wondering if there is a best practice when one needs to add extra JS code in a plugin.
I am creating an experiment, and would like to have some js functions to be executed once the experiment is loaded.
I need to declare a couple of js functions to be able to use on a onclick event of the html in my experiment.
For now, I tried including a <script> in my display_element, but it doesn't seem to work :/
thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions